@tempest/core
Version:
The core of the Tempest Stream Library
53 lines • 2.06 kB
JavaScript
import $$observable from 'symbol-observable';
import { Multicast } from './multicast/Multicast';
import { isArrayLike } from './util/array';
import { BasicSubscription } from './util/BasicSubscription';
import { SubscriberSink } from './util/SubscriberSink';
import { FromArraySource } from './source/fromArray';
import { FromObservableSource } from './source/fromObservable';
export class Stream {
constructor(source) {
this.source = new Multicast(source);
}
static from(input) {
if (typeof input[$$observable] === 'function') {
return new Stream(new FromObservableSource(input));
}
else if (isArrayLike(input)) {
return new Stream(new FromArraySource(input));
}
else {
throw new Error('Stream can only be made from an Observable or ArrayLike object');
}
}
static of(...items) {
return Stream.from(items);
}
subscribe(nextOrSubscriber, error, complete) {
let _next = Function.prototype;
let _error = Function.prototype;
let _complete = Function.prototype;
if (nextOrSubscriber !== null && typeof nextOrSubscriber === 'object') {
const subscriber = nextOrSubscriber;
const { next, error, complete } = subscriber;
if (next && typeof next === 'function')
_next = next;
if (error && typeof error === 'function')
_error = error;
if (complete && typeof complete === 'function')
_complete = complete;
}
else if (typeof nextOrSubscriber === 'function') {
_next = nextOrSubscriber;
if (error && typeof error === 'function')
_error = error;
if (complete && typeof complete === 'function')
_complete = complete;
}
return BasicSubscription.create(this.source, SubscriberSink.create(_next, _error, _complete));
}
[$$observable]() {
return this;
}
}
//# sourceMappingURL=Stream.js.map