flinker 1.0.0 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RX.d.ts +22 -0
- package/dist/RXObserver.d.ts +33 -0
- package/dist/RXOperator.d.ts +133 -0
- package/dist/RXPipeline.d.ts +14 -0
- package/dist/RXPublisher.d.ts +153 -0
- package/dist/RXSubscriber.d.ts +30 -0
- package/dist/cjs/RX.js +41 -0
- package/dist/cjs/RXObserver.js +255 -0
- package/dist/cjs/RXOperator.js +484 -0
- package/dist/cjs/RXPipeline.js +27 -0
- package/dist/cjs/RXPublisher.js +733 -0
- package/dist/cjs/RXSubscriber.js +77 -0
- package/dist/cjs/index.js +50 -0
- package/dist/esm/RX.js +38 -0
- package/dist/esm/RXObserver.js +249 -0
- package/dist/esm/RXOperator.js +481 -0
- package/dist/esm/RXPipeline.js +24 -0
- package/dist/esm/RXPublisher.js +730 -0
- package/dist/esm/RXSubscriber.js +74 -0
- package/dist/esm/index.js +7 -0
- package/dist/index.d.ts +7 -0
- package/package.json +2 -2
package/dist/RX.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type RXAnyOperatorProtocol } from './RXOperator.js';
|
|
2
|
+
import { type AnyRXObservable, type RXObservable, RXQueue } from './RXPublisher.js';
|
|
3
|
+
export type RXObjectType = 'operator' | 'observable' | 'pipeline' | 'object';
|
|
4
|
+
export interface RXObject {
|
|
5
|
+
type: RXObjectType;
|
|
6
|
+
}
|
|
7
|
+
export type RXAnySender = RXSender<any, any>;
|
|
8
|
+
export interface RXSender<V, E> {
|
|
9
|
+
send(value: V, broadcast: boolean): void;
|
|
10
|
+
sendError(e: E, broadcast: boolean): void;
|
|
11
|
+
sendComplete(broadcast: boolean): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class RX {
|
|
14
|
+
static combine(...list: Array<AnyRXObservable | RXAnyOperatorProtocol>): RXObservable<any[], any>;
|
|
15
|
+
static from<V, E>(list: V[]): RXObservable<V, E>;
|
|
16
|
+
static queue<V, E>(): RXQueue<V, E>;
|
|
17
|
+
static waitUntilComplete<V, E>(list: AnyRXObservable[] | AnyRXObservable, result?: RXObservable<V, E>): RXObservable<V, E>;
|
|
18
|
+
static justComplete<V, E>(value?: V): RXObservable<V, E>;
|
|
19
|
+
static justError<V, E>(error: E): RXObservable<V, E>;
|
|
20
|
+
static delayedComplete<V, E>(ms: number, value?: V): RXObservable<V, E>;
|
|
21
|
+
static delayedError<V, E>(ms: number, error: E): RXObservable<V, E>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type AnyRXObservable, type RXObservable } from './RXPublisher.js';
|
|
2
|
+
export declare function observe<RXElement extends AnyRXObservable | undefined>(rx: RXElement): RXElement;
|
|
3
|
+
export declare function observeFrom(rx: () => AnyRXObservable): void;
|
|
4
|
+
export declare function observer<T>(component: (props: T) => React.JSX.Element): (props: T) => React.JSX.Element;
|
|
5
|
+
type JSXSubscriberUID = number;
|
|
6
|
+
export declare class JSXSubscriber {
|
|
7
|
+
static readonly empty: JSXSubscriber;
|
|
8
|
+
readonly uid: JSXSubscriberUID;
|
|
9
|
+
private readonly buildersSet;
|
|
10
|
+
private readonly unsubscribeColl;
|
|
11
|
+
renderCycle: number;
|
|
12
|
+
initialized: boolean;
|
|
13
|
+
readonly forceRenderFunc: (renderCycle: number) => void;
|
|
14
|
+
constructor(forceRenderFunc: (renderCycle: number) => void);
|
|
15
|
+
private _isDisposed;
|
|
16
|
+
get isDisposed(): boolean;
|
|
17
|
+
observe<V, E>(b: RXObservable<V, E>): void;
|
|
18
|
+
observeFrom(f: () => AnyRXObservable): void;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
resurrect(): void;
|
|
21
|
+
render(renderCycle: number): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class ObservableGlobalState {
|
|
24
|
+
static renderCycle: number;
|
|
25
|
+
static initializingJSXComponent: JSXSubscriber;
|
|
26
|
+
static debug: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare enum RenderQueueStatus {
|
|
29
|
+
IDLE = "IDLE",
|
|
30
|
+
PENDING = "PENDING",
|
|
31
|
+
RUNNING = "LOADING"
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type RXObservable } from './RXPublisher.js';
|
|
2
|
+
import { type RXAnyPipeline, type RXPipeline } from './RXPipeline';
|
|
3
|
+
import { type CompleteMethod, type ErrorMethod, type SubscribeMethod } from './RXSubscriber.js';
|
|
4
|
+
import { type RXAnySender, type RXObject, type RXObjectType, type RXSender } from './RX.js';
|
|
5
|
+
export interface RXOperatorProtocol<V, E> extends RXObject {
|
|
6
|
+
skipFirst(): RXOperatorProtocol<V, E>;
|
|
7
|
+
skipNullable(): RXOperatorProtocol<NonNullable<V>, E>;
|
|
8
|
+
removeDuplicates(defValue?: V): RXOperatorProtocol<V, E>;
|
|
9
|
+
debounce(ms: number): RXOperatorProtocol<V, E>;
|
|
10
|
+
map<T>(f: (v: V) => T): RXOperatorProtocol<T, E>;
|
|
11
|
+
flatMap<T>(f: (v: V) => RXObservable<T, E>): RXOperatorProtocol<T, E>;
|
|
12
|
+
forEach<T>(f: (v: V) => RXObservable<T, E>): RXOperatorProtocol<T, E>;
|
|
13
|
+
sequent<T>(f: (v: V) => RXObservable<T, E>): RXOperatorProtocol<T, E>;
|
|
14
|
+
parallel<T>(f: (v: V) => RXObservable<T, E>): RXOperatorProtocol<T, E>;
|
|
15
|
+
filter(predicate: (v: V) => boolean): RXOperatorProtocol<V, E>;
|
|
16
|
+
spread(): RXOperatorProtocol<ArrayElementTypeOf<V>, E>;
|
|
17
|
+
replaceError(replaceWith: (e: E) => V | null): RXOperatorProtocol<V, E>;
|
|
18
|
+
fork(): RXObservable<V, E>;
|
|
19
|
+
onReceive(f: (v: V) => void): ErrorMethod<E> & CompleteMethod & SubscribeMethod;
|
|
20
|
+
onError(f: (e: E) => void): CompleteMethod & SubscribeMethod;
|
|
21
|
+
onComplete(f: () => void): SubscribeMethod;
|
|
22
|
+
}
|
|
23
|
+
type ArrayElementTypeOf<T> = T extends Array<infer U> ? U : T;
|
|
24
|
+
export type RXAnyOperator = RXOperator<any, any>;
|
|
25
|
+
export type RXAnyOperatorProtocol = RXOperatorProtocol<any, any>;
|
|
26
|
+
export declare class RXOperator<V, E> implements RXOperatorProtocol<V, E>, RXSender<V, E> {
|
|
27
|
+
protected pipeline: RXAnyPipeline;
|
|
28
|
+
protected child?: RXAnySender;
|
|
29
|
+
readonly type: RXObjectType;
|
|
30
|
+
constructor(pipeline: RXPipeline<V, E>);
|
|
31
|
+
protected _isComplete: boolean;
|
|
32
|
+
get isComplete(): boolean;
|
|
33
|
+
send(value: any, broadcast: boolean): void;
|
|
34
|
+
sendError(e: E, broadcast: boolean): void;
|
|
35
|
+
sendComplete(broadcast: boolean): void;
|
|
36
|
+
skipFirst(): RXOperator<V, E>;
|
|
37
|
+
skipNullable(): RXOperator<NonNullable<V>, E>;
|
|
38
|
+
removeDuplicates(value?: V): RXOperator<V, E>;
|
|
39
|
+
debounce(ms: number): RXOperator<V, E>;
|
|
40
|
+
map<T>(f: (v: V) => T): RXOperator<T, E>;
|
|
41
|
+
flatMap<T>(f: (v: V) => RXObservable<T, E>): RXOperator<T, E>;
|
|
42
|
+
forEach<T>(f: (v: V) => RXObservable<T, E>): RXOperator<T, E>;
|
|
43
|
+
sequent<T>(f: (v: V) => RXObservable<T, E>): RXOperator<T, E>;
|
|
44
|
+
parallel<T>(f: (v: V) => RXObservable<T, E>): RXOperator<T, E>;
|
|
45
|
+
filter(predicate: (v: V) => boolean): RXOperator<V, E>;
|
|
46
|
+
spread(): RXOperator<ArrayElementTypeOf<V>, E>;
|
|
47
|
+
replaceError(replaceWith: (e: E) => V | null): RXOperator<V, E>;
|
|
48
|
+
private addChild;
|
|
49
|
+
fork(): RXObservable<V, E>;
|
|
50
|
+
onReceive(f: (v: V) => void): ErrorMethod<E> & CompleteMethod & SubscribeMethod;
|
|
51
|
+
onError(f: (e: E) => void): CompleteMethod & SubscribeMethod;
|
|
52
|
+
onComplete(f: () => void): SubscribeMethod;
|
|
53
|
+
}
|
|
54
|
+
export declare class RXMap<V, E> extends RXOperator<V, E> {
|
|
55
|
+
protected mapper: (value: any) => V;
|
|
56
|
+
constructor(pipe: RXAnyPipeline, mapper: (value: any) => V);
|
|
57
|
+
send(value: any, broadcast: boolean): void;
|
|
58
|
+
}
|
|
59
|
+
export declare class RXFlatMap<V, E> extends RXOperator<V, E> {
|
|
60
|
+
protected mapper: (value: any) => RXObservable<V, E>;
|
|
61
|
+
constructor(pipe: RXAnyPipeline, mapper: (value: any) => RXObservable<V, E>);
|
|
62
|
+
send(value: any, broadcast: boolean): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class RXForEach<V, E> extends RXOperator<V, E> {
|
|
65
|
+
protected mapper: (value: any) => RXObservable<V, E>;
|
|
66
|
+
private readonly buffer;
|
|
67
|
+
private willComplete;
|
|
68
|
+
private willCompleteBroadcast;
|
|
69
|
+
constructor(pipe: RXAnyPipeline, mapper: (value: any) => RXObservable<V, E>);
|
|
70
|
+
send(value: any, broadcast: boolean): void;
|
|
71
|
+
sendError(error: E, broadcast: boolean): void;
|
|
72
|
+
sendComplete(broadcast: boolean): void;
|
|
73
|
+
private curOp;
|
|
74
|
+
private processNext;
|
|
75
|
+
}
|
|
76
|
+
export declare class RXSequent<V, E> extends RXOperator<V, E> {
|
|
77
|
+
protected mapper: (value: any) => RXObservable<V, E>;
|
|
78
|
+
private readonly buffer;
|
|
79
|
+
private willComplete;
|
|
80
|
+
private willCompleteBroadcast;
|
|
81
|
+
constructor(pipe: RXAnyPipeline, mapper: (value: any) => RXObservable<V, E>);
|
|
82
|
+
send(value: any, broadcast: boolean): void;
|
|
83
|
+
sendError(error: E, broadcast: boolean): void;
|
|
84
|
+
sendComplete(broadcast: boolean): void;
|
|
85
|
+
private curOp;
|
|
86
|
+
private processNext;
|
|
87
|
+
}
|
|
88
|
+
export declare class RXParallel<V, E> extends RXOperator<V, E> {
|
|
89
|
+
protected mapper: (value: any) => RXObservable<V, E>;
|
|
90
|
+
private willComplete;
|
|
91
|
+
private willCompleteBroadcast;
|
|
92
|
+
private activeOperations;
|
|
93
|
+
constructor(pipe: RXAnyPipeline, mapper: (value: any) => RXObservable<V, E>);
|
|
94
|
+
send(value: any, broadcast: boolean): void;
|
|
95
|
+
sendComplete(broadcast: boolean): void;
|
|
96
|
+
}
|
|
97
|
+
export declare class RXFilter<V, E> extends RXOperator<V, E> {
|
|
98
|
+
protected predicate: (value: V) => boolean;
|
|
99
|
+
constructor(pipe: RXAnyPipeline, predicate: (value: V) => boolean);
|
|
100
|
+
send(value: any, broadcast: boolean): void;
|
|
101
|
+
}
|
|
102
|
+
export declare class RXSpread<V, E> extends RXOperator<V, E> {
|
|
103
|
+
send(value: any, broadcast: boolean): void;
|
|
104
|
+
}
|
|
105
|
+
export declare class RXSkipFirst<V, E> extends RXOperator<V, E> {
|
|
106
|
+
send(value: any, broadcast: boolean): void;
|
|
107
|
+
}
|
|
108
|
+
export declare class RXSkipNullable<V, E> extends RXOperator<V, E> {
|
|
109
|
+
send(value: any, broadcast: boolean): void;
|
|
110
|
+
}
|
|
111
|
+
export declare class RXRemoveDuplicates<V, E> extends RXOperator<V, E> {
|
|
112
|
+
private prevValue;
|
|
113
|
+
constructor(pipe: RXAnyPipeline, value?: V);
|
|
114
|
+
send(value: any, broadcast: boolean): void;
|
|
115
|
+
}
|
|
116
|
+
export declare class RXDebounce<V, E> extends RXOperator<V, E> {
|
|
117
|
+
readonly ms: number;
|
|
118
|
+
constructor(pipe: RXAnyPipeline, ms: number);
|
|
119
|
+
private readonly buffer;
|
|
120
|
+
private willComplete;
|
|
121
|
+
private willCompleteBroadcast;
|
|
122
|
+
private timeoutId;
|
|
123
|
+
private startTimer;
|
|
124
|
+
send(value: any, broadcast: boolean): void;
|
|
125
|
+
sendError(error: E, broadcast: boolean): void;
|
|
126
|
+
sendComplete(broadcast: boolean): void;
|
|
127
|
+
}
|
|
128
|
+
export declare class RXReplaceError<V, E> extends RXOperator<V, E> {
|
|
129
|
+
readonly replaceWith: (e: E) => V | null;
|
|
130
|
+
constructor(pipe: RXAnyPipeline, replaceWith: (e: E) => V | null);
|
|
131
|
+
sendError(e: E, broadcast: boolean): void;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RXPublisher } from './RXPublisher.js';
|
|
2
|
+
import { RXOperator, type RXOperatorProtocol } from './RXOperator.js';
|
|
3
|
+
import { type RXObject, type RXObjectType, type RXSender } from './RX.js';
|
|
4
|
+
export type RXAnyPipeline = RXPipeline<any, any>;
|
|
5
|
+
export declare class RXPipeline<V, E> implements RXSender<V, E>, RXObject {
|
|
6
|
+
readonly type: RXObjectType;
|
|
7
|
+
readonly dispatcher: RXPublisher<V, E>;
|
|
8
|
+
readonly child: RXOperator<V, E>;
|
|
9
|
+
get asOperator(): RXOperatorProtocol<V, E>;
|
|
10
|
+
constructor(dispatcher: RXPublisher<V, E>);
|
|
11
|
+
send(value: any, broadcast: boolean): void;
|
|
12
|
+
sendError(e: E, broadcast: boolean): void;
|
|
13
|
+
sendComplete(broadcast: boolean): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type RXAnyOperatorProtocol, type RXOperatorProtocol } from './RXOperator.js';
|
|
2
|
+
import { type RXAnyPipeline } from './RXPipeline';
|
|
3
|
+
import { type RXObject, type RXObjectType } from './RX';
|
|
4
|
+
export type AnyRXObservable = RXObservable<any, any>;
|
|
5
|
+
export interface RXObservable<V, E> extends RXObject {
|
|
6
|
+
suid: RXPublisherUID;
|
|
7
|
+
isComplete: boolean;
|
|
8
|
+
pipe(): RXOperatorProtocol<V, E>;
|
|
9
|
+
}
|
|
10
|
+
export type RXPublisherUID = number;
|
|
11
|
+
export type RXAnyPublisher = RXPublisher<any, any>;
|
|
12
|
+
export declare class RXPublisher<V, E> implements RXObservable<V, E> {
|
|
13
|
+
readonly suid: RXPublisherUID;
|
|
14
|
+
readonly type: RXObjectType;
|
|
15
|
+
protected readonly pipelines: RXAnyPipeline[];
|
|
16
|
+
constructor();
|
|
17
|
+
get volume(): number;
|
|
18
|
+
get asObservable(): RXObservable<V, E>;
|
|
19
|
+
protected _isComplete: boolean;
|
|
20
|
+
get isComplete(): boolean;
|
|
21
|
+
pipe(): RXOperatorProtocol<V, E>;
|
|
22
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
23
|
+
private readonly pendingUnsubscribePipes;
|
|
24
|
+
didUnsubscribe(p: RXAnyPipeline): void;
|
|
25
|
+
private isSending;
|
|
26
|
+
protected send(value: V): void;
|
|
27
|
+
protected sendError(e: E): void;
|
|
28
|
+
protected sendComplete(): void;
|
|
29
|
+
private runPendingOperations;
|
|
30
|
+
}
|
|
31
|
+
export declare class RXJustComplete<V, E> extends RXPublisher<V, E> {
|
|
32
|
+
readonly value?: V;
|
|
33
|
+
constructor(value?: V);
|
|
34
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class RXJustError<V, E> extends RXPublisher<V, E> {
|
|
37
|
+
readonly error: E;
|
|
38
|
+
constructor(error: E);
|
|
39
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
40
|
+
}
|
|
41
|
+
export declare class RXDelayedComplete<V, E> extends RXPublisher<V, E> {
|
|
42
|
+
readonly value?: V;
|
|
43
|
+
constructor(ms: number, value?: V);
|
|
44
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
45
|
+
}
|
|
46
|
+
export declare class RXDelayedError<V, E> extends RXPublisher<V, E> {
|
|
47
|
+
readonly error: E;
|
|
48
|
+
constructor(ms: number, error: E);
|
|
49
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
50
|
+
}
|
|
51
|
+
export declare class RXEmitter<V, E> extends RXPublisher<V, E> {
|
|
52
|
+
private _hasValue;
|
|
53
|
+
private _value;
|
|
54
|
+
get value(): V | undefined;
|
|
55
|
+
private hasError;
|
|
56
|
+
private _err;
|
|
57
|
+
get err(): E | undefined;
|
|
58
|
+
constructor();
|
|
59
|
+
send(value: V): void;
|
|
60
|
+
sendError(e: E): void;
|
|
61
|
+
sendComplete(): void;
|
|
62
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class RXSubject<V, E> extends RXPublisher<V, E> {
|
|
65
|
+
private _value;
|
|
66
|
+
get value(): V;
|
|
67
|
+
private _hasError;
|
|
68
|
+
private _err;
|
|
69
|
+
get err(): E | undefined;
|
|
70
|
+
constructor(value: V);
|
|
71
|
+
send(value: V): void;
|
|
72
|
+
resend(): void;
|
|
73
|
+
sendError(e: E): void;
|
|
74
|
+
sendComplete(): void;
|
|
75
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
76
|
+
}
|
|
77
|
+
export declare class RXBuffer<V, E> extends RXPublisher<V, E> {
|
|
78
|
+
private readonly values;
|
|
79
|
+
private readonly errors;
|
|
80
|
+
private readonly isError;
|
|
81
|
+
send(value: V): void;
|
|
82
|
+
sendError(e: E): void;
|
|
83
|
+
sendComplete(): void;
|
|
84
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
85
|
+
}
|
|
86
|
+
export declare class RXOperation<V, E> extends RXPublisher<V, E> {
|
|
87
|
+
private _value;
|
|
88
|
+
get value(): V | undefined;
|
|
89
|
+
private _hasError;
|
|
90
|
+
private _err;
|
|
91
|
+
get err(): E | undefined;
|
|
92
|
+
success(value: V): void;
|
|
93
|
+
fail(e: E): void;
|
|
94
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
95
|
+
}
|
|
96
|
+
export declare class RXCombine extends RXPublisher<any[], any> {
|
|
97
|
+
private readonly _values;
|
|
98
|
+
get values(): any[];
|
|
99
|
+
private _hasError;
|
|
100
|
+
private _err;
|
|
101
|
+
get err(): any | undefined;
|
|
102
|
+
constructor(list: Array<AnyRXObservable | RXAnyOperatorProtocol>);
|
|
103
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
104
|
+
}
|
|
105
|
+
export declare class RXFrom<V, E> extends RXPublisher<V, E> {
|
|
106
|
+
readonly values: V[];
|
|
107
|
+
constructor(list: V[]);
|
|
108
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
109
|
+
}
|
|
110
|
+
export declare class RXWaitUntilComplete<V, E> extends RXPublisher<V, E> {
|
|
111
|
+
private _value;
|
|
112
|
+
get value(): V | undefined;
|
|
113
|
+
private readonly _resultPublisher;
|
|
114
|
+
private _hasError;
|
|
115
|
+
private _err;
|
|
116
|
+
get err(): any | undefined;
|
|
117
|
+
constructor(list: AnyRXObservable[] | AnyRXObservable, resultPublisher?: RXObservable<V, E>);
|
|
118
|
+
private subscribeToResultPublisher;
|
|
119
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
120
|
+
}
|
|
121
|
+
export declare class RXObservableEntity<V> extends RXPublisher<V, any> {
|
|
122
|
+
protected mutated(): void;
|
|
123
|
+
protected send(value: any): void;
|
|
124
|
+
protected dispose(): void;
|
|
125
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
126
|
+
}
|
|
127
|
+
export declare class RXObservableValue<V> extends RXPublisher<V, any> {
|
|
128
|
+
private _value;
|
|
129
|
+
get value(): V;
|
|
130
|
+
set value(value: V);
|
|
131
|
+
constructor(value: V);
|
|
132
|
+
didSubscribe(p: RXAnyPipeline): void;
|
|
133
|
+
}
|
|
134
|
+
export type RXAnyQueueOperator = RXQueueOperator<any, any>;
|
|
135
|
+
export declare class RXQueueOperator<V, E> {
|
|
136
|
+
protected readonly op: RXOperation<any, E>;
|
|
137
|
+
protected child?: RXQueueOperator<V, E>;
|
|
138
|
+
protected inProgress: boolean;
|
|
139
|
+
protected value: V | undefined;
|
|
140
|
+
constructor(op: RXOperation<any, E>);
|
|
141
|
+
protected send(value: any): void;
|
|
142
|
+
next<T>(f: (v: V) => RXObservable<T, E>): RXQueueOperator<T, E>;
|
|
143
|
+
private addChild;
|
|
144
|
+
complete(): RXObservable<V, E>;
|
|
145
|
+
}
|
|
146
|
+
export declare class RXQueue<V, E> extends RXQueueOperator<void, E> {
|
|
147
|
+
constructor();
|
|
148
|
+
get asObservable(): RXObservable<V, E>;
|
|
149
|
+
get isComplete(): boolean;
|
|
150
|
+
next<T>(f: () => RXObservable<T, E>): RXQueueOperator<T, E>;
|
|
151
|
+
success(v: V): void;
|
|
152
|
+
fail(e: E): void;
|
|
153
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RXSender } from './RX.ts';
|
|
2
|
+
import { type RXAnyPipeline } from './RXPipeline.js';
|
|
3
|
+
export interface ErrorMethod<E> {
|
|
4
|
+
onError(callback: (e: E) => void): CompleteMethod & SubscribeMethod;
|
|
5
|
+
}
|
|
6
|
+
export interface CompleteMethod {
|
|
7
|
+
onComplete(callback: () => void): SubscribeMethod;
|
|
8
|
+
}
|
|
9
|
+
export interface SubscribeMethod {
|
|
10
|
+
subscribe(): () => void;
|
|
11
|
+
}
|
|
12
|
+
export type RXAnySubscriber = RXSubscriber<any, any>;
|
|
13
|
+
export declare class RXSubscriber<V, E> implements RXSender<V, E> {
|
|
14
|
+
private onReceiveCallback?;
|
|
15
|
+
private onErrorCallback?;
|
|
16
|
+
private onCompleteCallback?;
|
|
17
|
+
readonly pipeline: RXAnyPipeline;
|
|
18
|
+
constructor(pipeline: RXAnyPipeline);
|
|
19
|
+
private _isComplete;
|
|
20
|
+
get isComplete(): boolean;
|
|
21
|
+
send(value: V, broadcast: boolean): void;
|
|
22
|
+
sendError(e: E, broadcast: boolean): void;
|
|
23
|
+
sendComplete(broadcast: boolean): void;
|
|
24
|
+
onReceive(f: (v: any) => void): ErrorMethod<E> & CompleteMethod & SubscribeMethod;
|
|
25
|
+
onError(f: (e: E) => void): CompleteMethod & SubscribeMethod;
|
|
26
|
+
onComplete(f: () => void): SubscribeMethod;
|
|
27
|
+
private isSubscribed;
|
|
28
|
+
subscribe(): () => void;
|
|
29
|
+
unsubscribe(): void;
|
|
30
|
+
}
|
package/dist/cjs/RX.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RX = void 0;
|
|
4
|
+
var RXPublisher_js_1 = require("./RXPublisher.js");
|
|
5
|
+
var RX = /** @class */ (function () {
|
|
6
|
+
function RX() {
|
|
7
|
+
}
|
|
8
|
+
//--------------------------------------
|
|
9
|
+
// STATIC METHODS
|
|
10
|
+
//--------------------------------------
|
|
11
|
+
RX.combine = function () {
|
|
12
|
+
var list = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
list[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
return new RXPublisher_js_1.RXCombine(list).asObservable;
|
|
17
|
+
};
|
|
18
|
+
RX.from = function (list) {
|
|
19
|
+
return new RXPublisher_js_1.RXFrom(list).asObservable;
|
|
20
|
+
};
|
|
21
|
+
RX.queue = function () {
|
|
22
|
+
return new RXPublisher_js_1.RXQueue();
|
|
23
|
+
};
|
|
24
|
+
RX.waitUntilComplete = function (list, result) {
|
|
25
|
+
return new RXPublisher_js_1.RXWaitUntilComplete(list, result).asObservable;
|
|
26
|
+
};
|
|
27
|
+
RX.justComplete = function (value) {
|
|
28
|
+
return new RXPublisher_js_1.RXJustComplete(value).asObservable;
|
|
29
|
+
};
|
|
30
|
+
RX.justError = function (error) {
|
|
31
|
+
return new RXPublisher_js_1.RXJustError(error).asObservable;
|
|
32
|
+
};
|
|
33
|
+
RX.delayedComplete = function (ms, value) {
|
|
34
|
+
return new RXPublisher_js_1.RXDelayedComplete(ms, value).asObservable;
|
|
35
|
+
};
|
|
36
|
+
RX.delayedError = function (ms, error) {
|
|
37
|
+
return new RXPublisher_js_1.RXDelayedError(ms, error).asObservable;
|
|
38
|
+
};
|
|
39
|
+
return RX;
|
|
40
|
+
}());
|
|
41
|
+
exports.RX = RX;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RenderQueueStatus = exports.ObservableGlobalState = exports.JSXSubscriber = void 0;
|
|
13
|
+
exports.observe = observe;
|
|
14
|
+
exports.observeFrom = observeFrom;
|
|
15
|
+
exports.observer = observer;
|
|
16
|
+
var react_1 = require("react");
|
|
17
|
+
var __DEV__ = false;
|
|
18
|
+
/*
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
* GLOBAL OBSERVE METHODS
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* */
|
|
25
|
+
function observe(rx) {
|
|
26
|
+
if (rx) {
|
|
27
|
+
var jsxSubscriber = ObservableGlobalState.initializingJSXComponent;
|
|
28
|
+
if (jsxSubscriber !== JSXSubscriber.empty) {
|
|
29
|
+
logInfo('observe(' + rx.constructor.name + '), subscriber uid =', jsxSubscriber.uid);
|
|
30
|
+
jsxSubscriber.observe(rx);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
logWarn('observe(' + rx.constructor.name + ') is failed: JSX Function Component has not "observer" wrapper!');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return rx;
|
|
37
|
+
}
|
|
38
|
+
function observeFrom(rx) {
|
|
39
|
+
if (rx) {
|
|
40
|
+
var jsxSubscriber = ObservableGlobalState.initializingJSXComponent;
|
|
41
|
+
if (jsxSubscriber !== JSXSubscriber.empty) {
|
|
42
|
+
logInfo('observeFunc(' + rx.constructor.name + '), subscriber uid =', jsxSubscriber.uid);
|
|
43
|
+
jsxSubscriber.observeFrom(rx);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
logWarn('observeFunc(' + rx.constructor.name + ') is failed: JSX Function Component has not "observer" wrapper!');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function observer(component) {
|
|
51
|
+
return function (props) {
|
|
52
|
+
var subscriberRef = (0, react_1.useRef)(JSXSubscriber.empty);
|
|
53
|
+
var _a = (0, react_1.useState)(ObservableGlobalState.renderCycle), forceRender = _a[1];
|
|
54
|
+
if (subscriberRef.current === JSXSubscriber.empty) {
|
|
55
|
+
subscriberRef.current = new JSXSubscriber(function (renderCycle) {
|
|
56
|
+
forceRender(renderCycle);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (__DEV__) {
|
|
60
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
61
|
+
if (ObservableGlobalState.debug)
|
|
62
|
+
logInfo('Registering of unmounting [' + subscriberRef.current.uid + ']');
|
|
63
|
+
if (subscriberRef.current.isDisposed) {
|
|
64
|
+
if (ObservableGlobalState.debug)
|
|
65
|
+
logInfo('Disposed Subscriber [' + subscriberRef.current.uid + '] is resurrected');
|
|
66
|
+
subscriberRef.current.resurrect();
|
|
67
|
+
}
|
|
68
|
+
return function () {
|
|
69
|
+
if (ObservableGlobalState.debug)
|
|
70
|
+
logInfo('Subscriber [' + subscriberRef.current.uid + '] is unmounted and disposed');
|
|
71
|
+
subscriberRef.current.dispose();
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
(0, react_1.useLayoutEffect)(function () { return function () { subscriberRef.current.dispose(); }; }, []);
|
|
77
|
+
}
|
|
78
|
+
var parentGlobalComponent = ObservableGlobalState.initializingJSXComponent;
|
|
79
|
+
ObservableGlobalState.initializingJSXComponent = subscriberRef.current;
|
|
80
|
+
//initializing begin
|
|
81
|
+
subscriberRef.current.renderCycle = ObservableGlobalState.renderCycle;
|
|
82
|
+
var renderedComponent = component(props);
|
|
83
|
+
subscriberRef.current.initialized = true;
|
|
84
|
+
//initializing end
|
|
85
|
+
ObservableGlobalState.initializingJSXComponent = parentGlobalComponent;
|
|
86
|
+
return renderedComponent;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var suid = (function () { var value = 0; return function () { return value++; }; })();
|
|
90
|
+
var JSXSubscriber = /** @class */ (function () {
|
|
91
|
+
function JSXSubscriber(forceRenderFunc) {
|
|
92
|
+
this.buildersSet = new Set();
|
|
93
|
+
this.unsubscribeColl = Array();
|
|
94
|
+
this.renderCycle = -1;
|
|
95
|
+
this.initialized = false;
|
|
96
|
+
this._isDisposed = false;
|
|
97
|
+
this.uid = suid();
|
|
98
|
+
this.forceRenderFunc = forceRenderFunc;
|
|
99
|
+
}
|
|
100
|
+
Object.defineProperty(JSXSubscriber.prototype, "isDisposed", {
|
|
101
|
+
get: function () {
|
|
102
|
+
return this._isDisposed;
|
|
103
|
+
},
|
|
104
|
+
enumerable: false,
|
|
105
|
+
configurable: true
|
|
106
|
+
});
|
|
107
|
+
JSXSubscriber.prototype.observe = function (b) {
|
|
108
|
+
var _this = this;
|
|
109
|
+
if (b.isComplete || this.buildersSet.has(b.suid))
|
|
110
|
+
return;
|
|
111
|
+
this.buildersSet.add(b.suid);
|
|
112
|
+
this.unsubscribeColl.push(b.pipe()
|
|
113
|
+
.onReceive(function () {
|
|
114
|
+
RenderQueue.self.add(_this);
|
|
115
|
+
})
|
|
116
|
+
.subscribe());
|
|
117
|
+
};
|
|
118
|
+
JSXSubscriber.prototype.observeFrom = function (f) {
|
|
119
|
+
var _this = this;
|
|
120
|
+
if (this.initialized)
|
|
121
|
+
return;
|
|
122
|
+
this.unsubscribeColl.push(f().pipe()
|
|
123
|
+
.skipFirst()
|
|
124
|
+
.onReceive(function () {
|
|
125
|
+
RenderQueue.self.add(_this);
|
|
126
|
+
})
|
|
127
|
+
.subscribe());
|
|
128
|
+
};
|
|
129
|
+
JSXSubscriber.prototype.dispose = function () {
|
|
130
|
+
this._isDisposed = true;
|
|
131
|
+
if (!__DEV__)
|
|
132
|
+
this.unsubscribeColl.forEach(function (f) { f(); });
|
|
133
|
+
};
|
|
134
|
+
JSXSubscriber.prototype.resurrect = function () {
|
|
135
|
+
this._isDisposed = false;
|
|
136
|
+
};
|
|
137
|
+
JSXSubscriber.prototype.render = function (renderCycle) {
|
|
138
|
+
if (this.isDisposed || this.renderCycle === renderCycle) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.renderCycle = renderCycle;
|
|
143
|
+
logInfo('----::forceRenderFunc');
|
|
144
|
+
this.forceRenderFunc(this.renderCycle);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
JSXSubscriber.empty = new JSXSubscriber(function () { });
|
|
149
|
+
return JSXSubscriber;
|
|
150
|
+
}());
|
|
151
|
+
exports.JSXSubscriber = JSXSubscriber;
|
|
152
|
+
//--------------------------------------
|
|
153
|
+
// GlobalState
|
|
154
|
+
//--------------------------------------
|
|
155
|
+
var ObservableGlobalState = /** @class */ (function () {
|
|
156
|
+
function ObservableGlobalState() {
|
|
157
|
+
}
|
|
158
|
+
ObservableGlobalState.renderCycle = 0;
|
|
159
|
+
ObservableGlobalState.initializingJSXComponent = JSXSubscriber.empty;
|
|
160
|
+
ObservableGlobalState.debug = false;
|
|
161
|
+
return ObservableGlobalState;
|
|
162
|
+
}());
|
|
163
|
+
exports.ObservableGlobalState = ObservableGlobalState;
|
|
164
|
+
//--------------------------------------
|
|
165
|
+
// RenderQueue
|
|
166
|
+
//--------------------------------------
|
|
167
|
+
var RenderQueueStatus;
|
|
168
|
+
(function (RenderQueueStatus) {
|
|
169
|
+
RenderQueueStatus["IDLE"] = "IDLE";
|
|
170
|
+
RenderQueueStatus["PENDING"] = "PENDING";
|
|
171
|
+
RenderQueueStatus["RUNNING"] = "LOADING";
|
|
172
|
+
})(RenderQueueStatus || (exports.RenderQueueStatus = RenderQueueStatus = {}));
|
|
173
|
+
var RenderQueue = /** @class */ (function () {
|
|
174
|
+
function RenderQueue() {
|
|
175
|
+
this.temp = Array();
|
|
176
|
+
this.queue = new Set();
|
|
177
|
+
this.status = RenderQueueStatus.IDLE;
|
|
178
|
+
this.INFINITE_LOOP_LIMIT = 20;
|
|
179
|
+
this.infiniteLoopDetected = false;
|
|
180
|
+
this.loopRenderings = 0;
|
|
181
|
+
}
|
|
182
|
+
RenderQueue.prototype.add = function (s) {
|
|
183
|
+
var _this = this;
|
|
184
|
+
if (this.infiniteLoopDetected)
|
|
185
|
+
return;
|
|
186
|
+
if (this.status === RenderQueueStatus.RUNNING) {
|
|
187
|
+
this.temp.push(s);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
this.queue.add(s);
|
|
191
|
+
if (this.status === RenderQueueStatus.IDLE) {
|
|
192
|
+
this.status = RenderQueueStatus.PENDING;
|
|
193
|
+
setTimeout(function () {
|
|
194
|
+
_this.render();
|
|
195
|
+
}, 0);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
RenderQueue.prototype.render = function () {
|
|
200
|
+
var _this = this;
|
|
201
|
+
logInfo('RenderQueue:render: begin, cycle:', ObservableGlobalState.renderCycle);
|
|
202
|
+
this.status = RenderQueueStatus.RUNNING;
|
|
203
|
+
ObservableGlobalState.renderCycle++;
|
|
204
|
+
var renderedComponentsCount = 0;
|
|
205
|
+
Array.from(this.queue)
|
|
206
|
+
.sort(function (s1, s2) { return s1.uid - s2.uid; })
|
|
207
|
+
.forEach(function (subscriber) {
|
|
208
|
+
subscriber.render(ObservableGlobalState.renderCycle) && renderedComponentsCount++;
|
|
209
|
+
});
|
|
210
|
+
this.queue.clear();
|
|
211
|
+
this.status = RenderQueueStatus.IDLE;
|
|
212
|
+
if (this.temp.length > 0) {
|
|
213
|
+
this.loopRenderings++;
|
|
214
|
+
if (this.loopRenderings > 2) {
|
|
215
|
+
logWarn.apply(void 0, __spreadArray(__spreadArray(['Sending value from publisher while jsx-component is rendering may cause an infinite loop. Loop renderings:', this.loopRenderings,
|
|
216
|
+
'. Most active publishers: ['], this.temp.map(function (ob) { return ob.constructor.name; }), false), [']'], false));
|
|
217
|
+
}
|
|
218
|
+
if (this.loopRenderings < this.INFINITE_LOOP_LIMIT) {
|
|
219
|
+
this.temp.forEach(function (publisherUID) {
|
|
220
|
+
_this.add(publisherUID);
|
|
221
|
+
});
|
|
222
|
+
this.temp.length = 0;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
this.infiniteLoopDetected = true;
|
|
226
|
+
logWarn('--Infinite Loop! The possible reason: An executed jsx-component X invoked new rendering of a jsx-component, ' +
|
|
227
|
+
'that caused mutation in publisher, that trigger again force render of X');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
this.loopRenderings = 0;
|
|
232
|
+
}
|
|
233
|
+
logInfo('RenderQueue:render: end, renderedComponentsCount:', renderedComponentsCount);
|
|
234
|
+
};
|
|
235
|
+
RenderQueue.self = new RenderQueue();
|
|
236
|
+
return RenderQueue;
|
|
237
|
+
}());
|
|
238
|
+
//--------------------------------------
|
|
239
|
+
// logging
|
|
240
|
+
//--------------------------------------
|
|
241
|
+
var logInfo = function () {
|
|
242
|
+
var msg = [];
|
|
243
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
244
|
+
msg[_i] = arguments[_i];
|
|
245
|
+
}
|
|
246
|
+
if (ObservableGlobalState.debug)
|
|
247
|
+
console.log.apply(console, msg);
|
|
248
|
+
};
|
|
249
|
+
var logWarn = function () {
|
|
250
|
+
var msg = [];
|
|
251
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
252
|
+
msg[_i] = arguments[_i];
|
|
253
|
+
}
|
|
254
|
+
console.warn.apply(console, msg);
|
|
255
|
+
};
|