1 | export interface IStreamObserver<T> {
|
2 | next?(value: T): void;
|
3 | error?(error: any): void;
|
4 | complete?(): void;
|
5 | }
|
6 | export interface ISubscription {
|
7 | unsubscribe(): void;
|
8 | }
|
9 | export interface IObservableStream<T> {
|
10 | subscribe(observer?: IStreamObserver<T> | null): ISubscription;
|
11 | subscribe(observer?: ((value: T) => void) | null): ISubscription;
|
12 | }
|
13 | /**
|
14 | * Converts an expression to an observable stream (a.k.a. TC 39 Observable / RxJS observable).
|
15 | * The provided expression is tracked by mobx as long as there are subscribers, automatically
|
16 | * emitting when new values become available. The expressions respect (trans)actions.
|
17 | *
|
18 | * @example
|
19 | *
|
20 | * const user = observable({
|
21 | * firstName: "C.S",
|
22 | * lastName: "Lewis"
|
23 | * })
|
24 | *
|
25 | * Rx.Observable
|
26 | * .from(mobxUtils.toStream(() => user.firstname + user.lastName))
|
27 | * .scan(nameChanges => nameChanges + 1, 0)
|
28 | * .subscribe(nameChanges => console.log("Changed name ", nameChanges, "times"))
|
29 | *
|
30 | * @export
|
31 | * @template T
|
32 | * @param {() => T} expression
|
33 | * @param {boolean} fireImmediately (by default false)
|
34 | * @returns {IObservableStream<T>}
|
35 | */
|
36 | export declare function toStream<T>(expression: () => T, fireImmediately?: boolean): IObservableStream<T>;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | export declare function fromStream<T>(observable: IObservableStream<T>): IStreamListener<T | undefined>;
|
54 | export declare function fromStream<T, I>(observable: IObservableStream<T>, initialValue: I): IStreamListener<T | I>;
|
55 | export interface IStreamListener<T> {
|
56 | current: T;
|
57 | dispose(): void;
|
58 | }
|