evg_observable 2.15.0 → 2.15.2
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/package.json +2 -1
- package/src/outLib/AbstractSwitchCase.d.ts +8 -0
- package/src/outLib/AbstractSwitchCase.js +32 -0
- package/src/outLib/Collector.d.ts +11 -0
- package/src/outLib/Collector.js +41 -0
- package/src/outLib/FilterCollection.d.ts +17 -0
- package/src/outLib/FilterCollection.js +69 -0
- package/src/outLib/FunctionLibs.d.ts +6 -0
- package/src/outLib/FunctionLibs.js +53 -0
- package/src/outLib/Observable.d.ts +30 -0
- package/src/outLib/Observable.js +137 -0
- package/src/outLib/OrderedObservable.d.ts +11 -0
- package/src/outLib/OrderedObservable.js +47 -0
- package/src/outLib/OrderedSubscribeObject.d.ts +10 -0
- package/src/outLib/OrderedSubscribeObject.js +29 -0
- package/src/outLib/Pipe.d.ts +20 -0
- package/src/outLib/Pipe.js +80 -0
- package/src/outLib/SubscribeObject.d.ts +18 -0
- package/src/outLib/SubscribeObject.js +72 -0
- package/src/outLib/Types.d.ts +165 -0
- package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.d.ts +0 -37
- package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.js +0 -61
- package/src/outLib/src/Libraries/Observables/Collector.d.ts +0 -56
- package/src/outLib/src/Libraries/Observables/Collector.js +0 -86
- package/src/outLib/src/Libraries/Observables/FilterCollection.d.ts +0 -70
- package/src/outLib/src/Libraries/Observables/FilterCollection.js +0 -122
- package/src/outLib/src/Libraries/Observables/FunctionLibs.d.ts +0 -48
- package/src/outLib/src/Libraries/Observables/FunctionLibs.js +0 -101
- package/src/outLib/src/Libraries/Observables/Observable.d.ts +0 -160
- package/src/outLib/src/Libraries/Observables/Observable.js +0 -268
- package/src/outLib/src/Libraries/Observables/OrderedObservable.d.ts +0 -70
- package/src/outLib/src/Libraries/Observables/OrderedObservable.js +0 -106
- package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.d.ts +0 -53
- package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.js +0 -72
- package/src/outLib/src/Libraries/Observables/Pipe.d.ts +0 -108
- package/src/outLib/src/Libraries/Observables/Pipe.js +0 -161
- package/src/outLib/src/Libraries/Observables/SubscribeObject.d.ts +0 -83
- package/src/outLib/src/Libraries/Observables/SubscribeObject.js +0 -139
- package/src/outLib/src/Libraries/Observables/Types.d.ts +0 -727
- /package/src/outLib/{src/Libraries/Observables/Types.js → Types.js} +0 -0
- /package/src/outLib/{src/Libraries/Observables/index.d.ts → index.d.ts} +0 -0
- /package/src/outLib/{src/Libraries/Observables/index.js → index.js} +0 -0
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evg_observable",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.2",
|
|
4
4
|
"description": "Alternative fast and light library version - observable.",
|
|
5
5
|
"main": "src/outLib/index.js",
|
|
6
|
+
"types": "src/outLib/index.d.ts",
|
|
6
7
|
"directories": {
|
|
7
8
|
"test": "test"
|
|
8
9
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICallback, IChainContainer } from "./Types";
|
|
2
|
+
export declare abstract class SwitchCase<T, P extends IChainContainer, W> {
|
|
3
|
+
protected pipe: P;
|
|
4
|
+
protected counter: number;
|
|
5
|
+
constructor(pipe: P);
|
|
6
|
+
case(condition: ICallback<any>): W;
|
|
7
|
+
pushCases(conditions: ICallback<any>[]): W;
|
|
8
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwitchCase = void 0;
|
|
4
|
+
class SwitchCase {
|
|
5
|
+
pipe;
|
|
6
|
+
counter;
|
|
7
|
+
constructor(pipe) {
|
|
8
|
+
this.pipe = pipe;
|
|
9
|
+
this.counter = pipe.chain.length ? pipe.chain.length : 0;
|
|
10
|
+
}
|
|
11
|
+
case(condition) {
|
|
12
|
+
this.counter++;
|
|
13
|
+
const id = this.counter;
|
|
14
|
+
const chain = this.pipe.chain;
|
|
15
|
+
chain.push((data) => {
|
|
16
|
+
data.isAvailable = true;
|
|
17
|
+
if (condition(data.payload))
|
|
18
|
+
data.isBreak = true;
|
|
19
|
+
if (id === chain.length && !data.isBreak)
|
|
20
|
+
data.isAvailable = false;
|
|
21
|
+
});
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
pushCases(conditions) {
|
|
25
|
+
if (!Array.isArray(conditions))
|
|
26
|
+
return this;
|
|
27
|
+
for (let i = 0; i < conditions.length; i++)
|
|
28
|
+
this.case(conditions[i]);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.SwitchCase = SwitchCase;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ICollector, ISubscriptionLike } from "./Types";
|
|
2
|
+
export declare class Collector implements ICollector {
|
|
3
|
+
protected arr: ISubscriptionLike[];
|
|
4
|
+
private killed;
|
|
5
|
+
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
6
|
+
unsubscribe(subscriptionLike: ISubscriptionLike | undefined): void;
|
|
7
|
+
unsubscribeAll(): void | null;
|
|
8
|
+
size(): number;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
get isDestroyed(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collector = void 0;
|
|
4
|
+
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
|
+
class Collector {
|
|
6
|
+
arr = [];
|
|
7
|
+
killed = false;
|
|
8
|
+
collect(...subscriptionLikeList) {
|
|
9
|
+
if (!this.killed)
|
|
10
|
+
this.arr.push(...subscriptionLikeList);
|
|
11
|
+
}
|
|
12
|
+
unsubscribe(subscriptionLike) {
|
|
13
|
+
if (this.killed)
|
|
14
|
+
return;
|
|
15
|
+
subscriptionLike?.unsubscribe();
|
|
16
|
+
(0, FunctionLibs_1.quickDeleteFromArray)(this.arr, subscriptionLike);
|
|
17
|
+
}
|
|
18
|
+
unsubscribeAll() {
|
|
19
|
+
if (this.killed)
|
|
20
|
+
return;
|
|
21
|
+
const arr = this.arr;
|
|
22
|
+
for (let i = 0; i < arr.length; i++)
|
|
23
|
+
arr[i].unsubscribe();
|
|
24
|
+
arr.length = 0;
|
|
25
|
+
}
|
|
26
|
+
size() {
|
|
27
|
+
if (this.killed)
|
|
28
|
+
return 0;
|
|
29
|
+
return this.arr.length;
|
|
30
|
+
}
|
|
31
|
+
destroy() {
|
|
32
|
+
this.unsubscribeAll();
|
|
33
|
+
this.arr.length = 0;
|
|
34
|
+
this.arr = 0;
|
|
35
|
+
this.killed = true;
|
|
36
|
+
}
|
|
37
|
+
get isDestroyed() {
|
|
38
|
+
return this.killed;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Collector = Collector;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ICallback, IErrorCallback, IFilter, IFilterCase, IFilterChainCallback, IFilterPayload, IFilterResponse, IFilterSetup, IFilterSwitch } from "./Types";
|
|
2
|
+
import { SwitchCase } from "./AbstractSwitchCase";
|
|
3
|
+
export declare class FilterCollection<T> implements IFilter<T>, IFilterSwitch<T> {
|
|
4
|
+
chain: IFilterChainCallback[];
|
|
5
|
+
flow: IFilterPayload;
|
|
6
|
+
response: IFilterResponse;
|
|
7
|
+
private errHandler;
|
|
8
|
+
get isEmpty(): boolean;
|
|
9
|
+
private push;
|
|
10
|
+
filter(condition: ICallback<any>): IFilterSetup<T>;
|
|
11
|
+
pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
12
|
+
switch(): FilterSwitchCase<T>;
|
|
13
|
+
processChain(value: T): IFilterResponse;
|
|
14
|
+
addErrorHandler(errorHandler: IErrorCallback): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class FilterSwitchCase<T> extends SwitchCase<T, FilterCollection<T>, IFilterCase<T>> {
|
|
17
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterSwitchCase = exports.FilterCollection = void 0;
|
|
4
|
+
const AbstractSwitchCase_1 = require("./AbstractSwitchCase");
|
|
5
|
+
class FilterCollection {
|
|
6
|
+
chain = [];
|
|
7
|
+
flow = { isBreak: false, isAvailable: false, payload: null };
|
|
8
|
+
response = { isOK: false, payload: undefined };
|
|
9
|
+
errHandler;
|
|
10
|
+
get isEmpty() {
|
|
11
|
+
return !this.chain.length;
|
|
12
|
+
}
|
|
13
|
+
push(callback) {
|
|
14
|
+
this.chain.push(callback);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
filter(condition) {
|
|
18
|
+
return this.push((data) => condition(data.payload) && (data.isAvailable = true));
|
|
19
|
+
}
|
|
20
|
+
pushFilters(conditions) {
|
|
21
|
+
if (!Array.isArray(conditions))
|
|
22
|
+
return this;
|
|
23
|
+
for (let i = 0; i < conditions.length; i++)
|
|
24
|
+
this.filter(conditions[i]);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
switch() {
|
|
28
|
+
return new FilterSwitchCase(this);
|
|
29
|
+
}
|
|
30
|
+
processChain(value) {
|
|
31
|
+
const chain = this.chain;
|
|
32
|
+
const data = this.flow;
|
|
33
|
+
const response = this.response;
|
|
34
|
+
response.isOK = false;
|
|
35
|
+
response.payload = undefined;
|
|
36
|
+
data.payload = value;
|
|
37
|
+
data.isBreak = false;
|
|
38
|
+
try {
|
|
39
|
+
const len = chain.length;
|
|
40
|
+
for (let i = 0; i < len; i++) {
|
|
41
|
+
data.isAvailable = false;
|
|
42
|
+
chain[i](data);
|
|
43
|
+
if (!data.isAvailable)
|
|
44
|
+
return response;
|
|
45
|
+
if (data.isBreak)
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
if (this.errHandler) {
|
|
51
|
+
this.errHandler(err, "Filter.processChain ERROR:");
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log("Filter.processChain ERROR:", err);
|
|
55
|
+
}
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
response.isOK = true;
|
|
59
|
+
response.payload = data.payload;
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
addErrorHandler(errorHandler) {
|
|
63
|
+
this.errHandler = errorHandler;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.FilterCollection = FilterCollection;
|
|
67
|
+
class FilterSwitchCase extends AbstractSwitchCase_1.SwitchCase {
|
|
68
|
+
}
|
|
69
|
+
exports.FilterSwitchCase = FilterSwitchCase;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IListener, ISubscribeGroup, ISubscribeObject } from "./Types";
|
|
2
|
+
export declare function sortAscending(a: ISubscribeObject<any>, b: ISubscribeObject<any>): number;
|
|
3
|
+
export declare function sortDescending(a: ISubscribeObject<any>, b: ISubscribeObject<any>): number;
|
|
4
|
+
export declare function deleteFromArray<T>(arr: T[], component: T): boolean;
|
|
5
|
+
export declare function quickDeleteFromArray<T>(arr: T[], component: T): boolean;
|
|
6
|
+
export declare function getListener<T>(listenerGroup: ISubscribeGroup<T>): IListener<T>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortAscending = sortAscending;
|
|
4
|
+
exports.sortDescending = sortDescending;
|
|
5
|
+
exports.deleteFromArray = deleteFromArray;
|
|
6
|
+
exports.quickDeleteFromArray = quickDeleteFromArray;
|
|
7
|
+
exports.getListener = getListener;
|
|
8
|
+
function sortAscending(a, b) {
|
|
9
|
+
if (a.order > b.order)
|
|
10
|
+
return 1;
|
|
11
|
+
if (a.order < b.order)
|
|
12
|
+
return -1;
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
function sortDescending(a, b) {
|
|
16
|
+
if (a.order > b.order)
|
|
17
|
+
return -1;
|
|
18
|
+
if (a.order < b.order)
|
|
19
|
+
return 1;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
function deleteFromArray(arr, component) {
|
|
23
|
+
const index = arr.indexOf(component);
|
|
24
|
+
if (index === -1)
|
|
25
|
+
return false;
|
|
26
|
+
arr.splice(index, 1);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
function quickDeleteFromArray(arr, component) {
|
|
30
|
+
const index = arr.indexOf(component);
|
|
31
|
+
if (index === -1)
|
|
32
|
+
return false;
|
|
33
|
+
arr[index] = arr[arr.length - 1];
|
|
34
|
+
arr.length--;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
function getListener(listenerGroup) {
|
|
38
|
+
if (Array.isArray(listenerGroup)) {
|
|
39
|
+
const group = [];
|
|
40
|
+
for (let i = 0; i < listenerGroup.length; i++)
|
|
41
|
+
group.push(wrapListener(listenerGroup[i]));
|
|
42
|
+
return (data) => {
|
|
43
|
+
for (let i = 0; i < group.length; i++)
|
|
44
|
+
group[i](data);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return wrapListener(listenerGroup);
|
|
48
|
+
}
|
|
49
|
+
function wrapListener(listener) {
|
|
50
|
+
if ("next" in listener)
|
|
51
|
+
return (value) => listener.next(value);
|
|
52
|
+
return listener;
|
|
53
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IAddFilter, IErrorCallback, IFilterSetup, IObserver, ISetup, IStream, ISubscribeGroup, ISubscribeObject, ISubscriptionLike } from "./Types";
|
|
2
|
+
import { SubscribeObject } from "./SubscribeObject";
|
|
3
|
+
import { FilterCollection } from "./FilterCollection";
|
|
4
|
+
export declare class Observable<T> implements IObserver<T>, IStream<T>, IAddFilter<T> {
|
|
5
|
+
protected subs: ISubscribeObject<T>[];
|
|
6
|
+
protected enabled: boolean;
|
|
7
|
+
protected killed: boolean;
|
|
8
|
+
protected process: boolean;
|
|
9
|
+
protected trash: ISubscriptionLike[];
|
|
10
|
+
protected filters: FilterCollection<T>;
|
|
11
|
+
protected _value: T;
|
|
12
|
+
constructor(value: T);
|
|
13
|
+
addFilter(errorHandler?: IErrorCallback): IFilterSetup<T>;
|
|
14
|
+
disable(): void;
|
|
15
|
+
enable(): void;
|
|
16
|
+
get isEnable(): boolean;
|
|
17
|
+
next(value: T): void;
|
|
18
|
+
stream(values: T[]): void;
|
|
19
|
+
private clearTrash;
|
|
20
|
+
unSubscribe(listener: ISubscriptionLike): void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
unsubscribeAll(): void;
|
|
23
|
+
getValue(): T | undefined;
|
|
24
|
+
size(): number;
|
|
25
|
+
subscribe(observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
26
|
+
protected addObserver(subscribeObject: SubscribeObject<T>, observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): void;
|
|
27
|
+
protected isListener(listener: ISubscribeGroup<T>): boolean;
|
|
28
|
+
pipe(): ISetup<T> | undefined;
|
|
29
|
+
get isDestroyed(): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Observable = void 0;
|
|
4
|
+
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
|
+
const SubscribeObject_1 = require("./SubscribeObject");
|
|
6
|
+
const FilterCollection_1 = require("./FilterCollection");
|
|
7
|
+
class Observable {
|
|
8
|
+
subs = [];
|
|
9
|
+
enabled = true;
|
|
10
|
+
killed = false;
|
|
11
|
+
process = false;
|
|
12
|
+
trash = [];
|
|
13
|
+
filters = new FilterCollection_1.FilterCollection();
|
|
14
|
+
_value;
|
|
15
|
+
constructor(value) {
|
|
16
|
+
this._value = value;
|
|
17
|
+
}
|
|
18
|
+
addFilter(errorHandler) {
|
|
19
|
+
if (errorHandler)
|
|
20
|
+
this.filters.addErrorHandler(errorHandler);
|
|
21
|
+
return this.filters;
|
|
22
|
+
}
|
|
23
|
+
disable() {
|
|
24
|
+
this.enabled = false;
|
|
25
|
+
}
|
|
26
|
+
enable() {
|
|
27
|
+
this.enabled = true;
|
|
28
|
+
}
|
|
29
|
+
get isEnable() {
|
|
30
|
+
return this.enabled;
|
|
31
|
+
}
|
|
32
|
+
next(value) {
|
|
33
|
+
if (this.killed)
|
|
34
|
+
return;
|
|
35
|
+
if (!this.enabled)
|
|
36
|
+
return;
|
|
37
|
+
if (!this.subs.length)
|
|
38
|
+
return;
|
|
39
|
+
if (!this.filters.isEmpty && !this.filters.processChain(value).isOK)
|
|
40
|
+
return;
|
|
41
|
+
this.process = true;
|
|
42
|
+
this._value = value;
|
|
43
|
+
const subs = this.subs;
|
|
44
|
+
const len = subs.length;
|
|
45
|
+
for (let i = 0; i < len; i++)
|
|
46
|
+
subs[i].send(value);
|
|
47
|
+
this.process = false;
|
|
48
|
+
this.trash.length && this.clearTrash();
|
|
49
|
+
}
|
|
50
|
+
stream(values) {
|
|
51
|
+
if (this.killed)
|
|
52
|
+
return;
|
|
53
|
+
if (!this.enabled)
|
|
54
|
+
return;
|
|
55
|
+
for (let i = 0; i < values.length; i++)
|
|
56
|
+
this.next(values[i]);
|
|
57
|
+
}
|
|
58
|
+
clearTrash() {
|
|
59
|
+
const length = this.trash.length;
|
|
60
|
+
for (let i = 0; i < length; i++)
|
|
61
|
+
this.unSubscribe(this.trash[i]);
|
|
62
|
+
this.trash.length = 0;
|
|
63
|
+
}
|
|
64
|
+
unSubscribe(listener) {
|
|
65
|
+
if (this.killed)
|
|
66
|
+
return;
|
|
67
|
+
if (this.process && listener) {
|
|
68
|
+
this.trash.push(listener);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.subs && !(0, FunctionLibs_1.quickDeleteFromArray)(this.subs, listener);
|
|
72
|
+
}
|
|
73
|
+
destroy() {
|
|
74
|
+
if (this.killed)
|
|
75
|
+
return;
|
|
76
|
+
this.killed = true;
|
|
77
|
+
if (!this.process) {
|
|
78
|
+
this._value = null;
|
|
79
|
+
this.subs.length = 0;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
Promise.resolve().then(() => {
|
|
83
|
+
this._value = null;
|
|
84
|
+
this.subs.length = 0;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
unsubscribeAll() {
|
|
88
|
+
if (this.killed)
|
|
89
|
+
return;
|
|
90
|
+
if (this.process) {
|
|
91
|
+
const subs = this.subs;
|
|
92
|
+
for (let i = 0; i < subs.length; i++)
|
|
93
|
+
this.trash.push(subs[i]);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.subs.length = 0;
|
|
97
|
+
}
|
|
98
|
+
getValue() {
|
|
99
|
+
if (this.killed)
|
|
100
|
+
return undefined;
|
|
101
|
+
return this._value;
|
|
102
|
+
}
|
|
103
|
+
size() {
|
|
104
|
+
if (this.killed)
|
|
105
|
+
return 0;
|
|
106
|
+
return this.subs.length;
|
|
107
|
+
}
|
|
108
|
+
subscribe(observer, errorHandler) {
|
|
109
|
+
if (this.killed)
|
|
110
|
+
return undefined;
|
|
111
|
+
if (!this.isListener(observer))
|
|
112
|
+
return undefined;
|
|
113
|
+
const subscribeObject = new SubscribeObject_1.SubscribeObject(this, false);
|
|
114
|
+
this.addObserver(subscribeObject, observer, errorHandler);
|
|
115
|
+
return subscribeObject;
|
|
116
|
+
}
|
|
117
|
+
addObserver(subscribeObject, observer, errorHandler) {
|
|
118
|
+
subscribeObject.subscribe(observer, errorHandler);
|
|
119
|
+
this.subs.push(subscribeObject);
|
|
120
|
+
}
|
|
121
|
+
isListener(listener) {
|
|
122
|
+
if (this.killed)
|
|
123
|
+
return false;
|
|
124
|
+
return !!listener;
|
|
125
|
+
}
|
|
126
|
+
pipe() {
|
|
127
|
+
if (this.killed)
|
|
128
|
+
return undefined;
|
|
129
|
+
const subscribeObject = new SubscribeObject_1.SubscribeObject(this, true);
|
|
130
|
+
this.subs.push(subscribeObject);
|
|
131
|
+
return subscribeObject;
|
|
132
|
+
}
|
|
133
|
+
get isDestroyed() {
|
|
134
|
+
return this.killed;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.Observable = Observable;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Observable } from "./Observable";
|
|
2
|
+
import { IErrorCallback, IOrdered, IOrderedSetup, IOrderedSubscriptionLike, ISubscribeGroup, ISubscriptionLike } from "./Types";
|
|
3
|
+
export declare class OrderedObservable<T> extends Observable<T> implements IOrdered<T> {
|
|
4
|
+
private sortDirection;
|
|
5
|
+
setAscendingSort(): boolean;
|
|
6
|
+
setDescendingSort(): boolean;
|
|
7
|
+
sortByOrder(): boolean;
|
|
8
|
+
subscribe(listener: ISubscribeGroup<T>, errorHandler?: IErrorCallback): IOrderedSubscriptionLike | undefined;
|
|
9
|
+
pipe(): IOrderedSetup<T> | undefined;
|
|
10
|
+
unSubscribe(listener: ISubscriptionLike): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrderedObservable = void 0;
|
|
4
|
+
const Observable_1 = require("./Observable");
|
|
5
|
+
const FunctionLibs_1 = require("./FunctionLibs");
|
|
6
|
+
const OrderedSubscribeObject_1 = require("./OrderedSubscribeObject");
|
|
7
|
+
class OrderedObservable extends Observable_1.Observable {
|
|
8
|
+
sortDirection = FunctionLibs_1.sortAscending;
|
|
9
|
+
setAscendingSort() {
|
|
10
|
+
this.sortDirection = FunctionLibs_1.sortAscending;
|
|
11
|
+
return this.sortByOrder();
|
|
12
|
+
}
|
|
13
|
+
setDescendingSort() {
|
|
14
|
+
this.sortDirection = FunctionLibs_1.sortDescending;
|
|
15
|
+
return this.sortByOrder();
|
|
16
|
+
}
|
|
17
|
+
sortByOrder() {
|
|
18
|
+
if (this.killed)
|
|
19
|
+
return false;
|
|
20
|
+
this.subs.sort(this.sortDirection);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
subscribe(listener, errorHandler) {
|
|
24
|
+
if (!this.isListener(listener))
|
|
25
|
+
return undefined;
|
|
26
|
+
const subscribeObject = new OrderedSubscribeObject_1.OrderedSubscribeObject(this, false);
|
|
27
|
+
this.addObserver(subscribeObject, listener, errorHandler);
|
|
28
|
+
return subscribeObject;
|
|
29
|
+
}
|
|
30
|
+
pipe() {
|
|
31
|
+
if (this.killed)
|
|
32
|
+
return undefined;
|
|
33
|
+
const subscribeObject = new OrderedSubscribeObject_1.OrderedSubscribeObject(this, true);
|
|
34
|
+
this.subs.push(subscribeObject);
|
|
35
|
+
return subscribeObject;
|
|
36
|
+
}
|
|
37
|
+
unSubscribe(listener) {
|
|
38
|
+
if (this.killed)
|
|
39
|
+
return;
|
|
40
|
+
if (this.process && listener) {
|
|
41
|
+
this.trash.push(listener);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.subs && !(0, FunctionLibs_1.quickDeleteFromArray)(this.subs, listener);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.OrderedObservable = OrderedObservable;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SubscribeObject } from "./SubscribeObject";
|
|
2
|
+
import { IErrorCallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISetObservableValue } from "./Types";
|
|
3
|
+
import { OrderedObservable } from "./OrderedObservable";
|
|
4
|
+
export declare class OrderedSubscribeObject<T> extends SubscribeObject<T> implements IOrderedSetup<T> {
|
|
5
|
+
constructor(observable: OrderedObservable<T> | IOrdered<T>, isPipe?: boolean);
|
|
6
|
+
get order(): number;
|
|
7
|
+
set order(value: number);
|
|
8
|
+
subscribe(observer: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): IOrderedSubscriptionLike;
|
|
9
|
+
setOnce(): IOrderedSubscribe<T>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrderedSubscribeObject = void 0;
|
|
4
|
+
const SubscribeObject_1 = require("./SubscribeObject");
|
|
5
|
+
class OrderedSubscribeObject extends SubscribeObject_1.SubscribeObject {
|
|
6
|
+
constructor(observable, isPipe) {
|
|
7
|
+
super(observable, isPipe);
|
|
8
|
+
}
|
|
9
|
+
get order() {
|
|
10
|
+
return this._order;
|
|
11
|
+
}
|
|
12
|
+
set order(value) {
|
|
13
|
+
if (!this.observer ||
|
|
14
|
+
(this.observer && this.observer.isDestroyed)) {
|
|
15
|
+
this._order = undefined;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
this._order = value;
|
|
19
|
+
this.observer.sortByOrder();
|
|
20
|
+
}
|
|
21
|
+
subscribe(observer, errorHandler) {
|
|
22
|
+
super.subscribe(observer, errorHandler);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
setOnce() {
|
|
26
|
+
return super.setOnce();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.OrderedSubscribeObject = OrderedSubscribeObject;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ICallback, IChainCallback, IErrorCallback, IListener, IPipeCase, IPipePayload, ISetObservableValue, ISetup, ISubscribe, ISubscriptionLike } from "./Types";
|
|
2
|
+
import { SwitchCase } from "./AbstractSwitchCase";
|
|
3
|
+
export declare abstract class Pipe<T> implements ISubscribe<T> {
|
|
4
|
+
chain: IChainCallback[];
|
|
5
|
+
flow: IPipePayload;
|
|
6
|
+
abstract subscribe(listener: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
7
|
+
private push;
|
|
8
|
+
setOnce(): ISubscribe<T>;
|
|
9
|
+
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
10
|
+
refine(condition: ICallback<T>): ISetup<T>;
|
|
11
|
+
pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
|
|
12
|
+
switch(): PipeSwitchCase<T>;
|
|
13
|
+
then<K>(condition: ICallback<T>): ISetup<K>;
|
|
14
|
+
serialize(): ISetup<string>;
|
|
15
|
+
deserialize<K>(): ISetup<K>;
|
|
16
|
+
processChain(listener: IListener<T>): void;
|
|
17
|
+
}
|
|
18
|
+
export declare class PipeSwitchCase<T> extends SwitchCase<T, Pipe<T>, IPipeCase<T>> implements ISubscribe<T> {
|
|
19
|
+
subscribe(listener: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PipeSwitchCase = exports.Pipe = void 0;
|
|
4
|
+
const AbstractSwitchCase_1 = require("./AbstractSwitchCase");
|
|
5
|
+
class Pipe {
|
|
6
|
+
chain = [];
|
|
7
|
+
flow = { isBreak: false, isUnsubscribe: false, isAvailable: false, payload: null };
|
|
8
|
+
push(callback) {
|
|
9
|
+
this.chain.push(callback);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
setOnce() {
|
|
13
|
+
return this.push((data) => {
|
|
14
|
+
this.listener(data.payload);
|
|
15
|
+
data.isUnsubscribe = true;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
unsubscribeBy(condition) {
|
|
19
|
+
return this.push((data) => {
|
|
20
|
+
data.isAvailable = true;
|
|
21
|
+
if (condition(data.payload))
|
|
22
|
+
data.isUnsubscribe = true;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
refine(condition) {
|
|
26
|
+
return this.push((data) => condition(data.payload) && (data.isAvailable = true));
|
|
27
|
+
}
|
|
28
|
+
pushRefiners(conditions) {
|
|
29
|
+
if (!Array.isArray(conditions))
|
|
30
|
+
return this;
|
|
31
|
+
for (let i = 0; i < conditions.length; i++)
|
|
32
|
+
this.refine(conditions[i]);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
switch() {
|
|
36
|
+
return new PipeSwitchCase(this);
|
|
37
|
+
}
|
|
38
|
+
then(condition) {
|
|
39
|
+
return this.push((data) => {
|
|
40
|
+
data.payload = condition(data.payload);
|
|
41
|
+
data.isAvailable = true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
serialize() {
|
|
45
|
+
return this.push((data) => {
|
|
46
|
+
data.payload = JSON.stringify(data.payload);
|
|
47
|
+
data.isAvailable = true;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
deserialize() {
|
|
51
|
+
return this.push((data) => {
|
|
52
|
+
data.payload = JSON.parse(data.payload);
|
|
53
|
+
data.isAvailable = true;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
processChain(listener) {
|
|
57
|
+
const chain = this.chain;
|
|
58
|
+
const data = this.flow;
|
|
59
|
+
const len = chain.length;
|
|
60
|
+
for (let i = 0; i < len; i++) {
|
|
61
|
+
data.isUnsubscribe = false;
|
|
62
|
+
data.isAvailable = false;
|
|
63
|
+
chain[i](data);
|
|
64
|
+
if (data.isUnsubscribe)
|
|
65
|
+
return this.unsubscribe();
|
|
66
|
+
if (!data.isAvailable)
|
|
67
|
+
return;
|
|
68
|
+
if (data.isBreak)
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return listener(data.payload);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.Pipe = Pipe;
|
|
75
|
+
class PipeSwitchCase extends AbstractSwitchCase_1.SwitchCase {
|
|
76
|
+
subscribe(listener, errorHandler) {
|
|
77
|
+
return this.pipe.subscribe(listener, errorHandler);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.PipeSwitchCase = PipeSwitchCase;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IErrorCallback, IListener, IObserver, ISubscribeGroup, ISubscribeObject, ISubscriptionLike } from "./Types";
|
|
2
|
+
import { Pipe } from "./Pipe";
|
|
3
|
+
export declare class SubscribeObject<T> extends Pipe<T> implements ISubscribeObject<T> {
|
|
4
|
+
observer: IObserver<T> | undefined;
|
|
5
|
+
listener: IListener<T> | undefined;
|
|
6
|
+
errorHandler: IErrorCallback;
|
|
7
|
+
_order: number;
|
|
8
|
+
paused: boolean;
|
|
9
|
+
piped: boolean;
|
|
10
|
+
constructor(observable?: IObserver<T>, isPipe?: boolean);
|
|
11
|
+
subscribe(observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike;
|
|
12
|
+
unsubscribe(): void;
|
|
13
|
+
send(value: T): void;
|
|
14
|
+
resume(): void;
|
|
15
|
+
pause(): void;
|
|
16
|
+
get order(): number;
|
|
17
|
+
set order(value: number);
|
|
18
|
+
}
|