export interface IStreamObserver { next?(value: T): void; error?(error: any): void; complete?(): void; } export interface ISubscription { unsubscribe(): void; } export interface IObservableStream { subscribe(observer?: IStreamObserver | null): ISubscription; subscribe(observer?: ((value: T) => void) | null): ISubscription; } /** * Converts an expression to an observable stream (a.k.a. TC 39 Observable / RxJS observable). * The provided expression is tracked by mobx as long as there are subscribers, automatically * emitting when new values become available. The expressions respect (trans)actions. * * @example * * const user = observable({ * firstName: "C.S", * lastName: "Lewis" * }) * * Rx.Observable * .from(mobxUtils.toStream(() => user.firstname + user.lastName)) * .scan(nameChanges => nameChanges + 1, 0) * .subscribe(nameChanges => console.log("Changed name ", nameChanges, "times")) * * @export * @template T * @param {() => T} expression * @param {boolean} fireImmediately (by default false) * @returns {IObservableStream} */ export declare function toStream(expression: () => T, fireImmediately?: boolean): IObservableStream; /** * Converts a subscribable, observable stream (TC 39 observable / RxJS stream) * into an object which stores the current value (as `current`). The subscription can be cancelled through the `dispose` method. * Takes an initial value as second optional argument * * @example * const debouncedClickDelta = MobxUtils.fromStream(Rx.Observable.fromEvent(button, 'click') * .throttleTime(1000) * .map(event => event.clientX) * .scan((count, clientX) => count + clientX, 0) * ) * * autorun(() => { * console.log("distance moved", debouncedClickDelta.current) * }) */ export declare function fromStream(observable: IObservableStream): IStreamListener; export declare function fromStream(observable: IObservableStream, initialValue: I): IStreamListener; export interface IStreamListener { current: T; dispose(): void; }