evg_observable 2.14.58 → 2.14.60
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 +1 -1
- package/repo/evg_observable.js +1 -1
- package/src/outLib/Collector.d.ts +2 -2
- package/src/outLib/Collector.js +15 -15
- package/src/outLib/FilterCollection.js +1 -4
- package/src/outLib/FunctionLibs.d.ts +5 -5
- package/src/outLib/FunctionLibs.js +13 -14
- package/src/outLib/Observable.d.ts +5 -5
- package/src/outLib/Observable.js +50 -40
- package/src/outLib/OrderedObservable.js +7 -7
- package/src/outLib/OrderedSubscribeObject.js +3 -3
- package/src/outLib/Pipe.js +1 -4
- package/src/outLib/SubscribeObject.d.ts +3 -3
- package/src/outLib/SubscribeObject.js +13 -13
package/package.json
CHANGED
package/repo/evg_observable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";
|
|
1
|
+
(()=>{"use strict";function s(s,r){return s.order>r.order?1:s.order<r.order?-1:0}function r(s,r){return s.order>r.order?-1:s.order<r.order?1:0}function e(s,r){const e=s.indexOf(r);return-1!==e&&(s[e]=s[s.length-1],s.length=s.length-1,!0)}function t(s){return"next"in s?r=>s.next(r):s}class i{constructor(s){this.pipe=s,this.counter=s.chain.length?s.chain.length:0}case(s){this.counter++;const r=this.counter,e=this.pipe.chain;return e.push((t=>{t.isAvailable=!0,s(t.payload)&&(t.isBreak=!0),r!==e.length||t.isBreak||(t.isAvailable=!1)})),this}pushCases(s){if(!Array.isArray(s))return this;for(let r=0;r<s.length;r++)this.case(s[r]);return this}}class h{constructor(){this.chain=[],this.flow={isBreak:!1,isUnsubscribe:!1,isAvailable:!1,payload:null}}push(s){return this.chain.push(s),this}setOnce(){return this.push((s=>{this.listener(s.payload),s.isUnsubscribe=!0}))}unsubscribeBy(s){return this.push((r=>{r.isAvailable=!0,s(r.payload)&&(r.isUnsubscribe=!0)}))}refine(s){return this.push((r=>s(r.payload)&&(r.isAvailable=!0)))}pushRefiners(s){if(!Array.isArray(s))return this;for(let r=0;r<s.length;r++)this.refine(s[r]);return this}switch(){return new n(this)}then(s){return this.push((r=>{r.payload=s(r.payload),r.isAvailable=!0}))}serialize(){return this.push((s=>{s.payload=JSON.stringify(s.payload),s.isAvailable=!0}))}deserialize(){return this.push((s=>{s.payload=JSON.parse(s.payload),s.isAvailable=!0}))}processChain(s){const r=this.chain,e=this.flow;for(let s=0;s<r.length;s++){if(e.isUnsubscribe=!1,e.isAvailable=!1,r[s](e),e.isUnsubscribe)return this.unsubscribe();if(!e.isAvailable)return;if(e.isBreak)break}return s(e.payload)}}class n extends i{subscribe(s,r){return this.pipe.subscribe(s,r)}}class l extends h{constructor(s,r){super(),this.errorHandler=(s,r)=>{console.log(`(Unit of SubscribeObject).send(${s}) ERROR:`,r)},this._order=0,this.paused=!1,this.piped=!1,this.observer=s,this.piped=!!r}subscribe(s,r){return this.listener=function(s){if(Array.isArray(s)){const r=[];for(let e=0;e<s.length;e++)r.push(t(s[e]));return s=>{for(let e=0;e<r.length;e++)r[e](s)}}return t(s)}(s),r&&(this.errorHandler=r),this}unsubscribe(){this.observer&&(this.observer.unSubscribe(this),this.observer=null,this.listener=null,this.chain.length=0)}send(s){try{this.flow.payload=s,this.flow.isBreak=!1,this.processValue(s)}catch(r){this.errorHandler(s,r)}}resume(){this.paused=!1}pause(){this.paused=!0}get order(){return this._order}set order(s){this._order=s}processValue(s){const r=this.listener;return r?this.observer&&!this.paused?this.piped?this.processChain(r):r(s):void 0:this.unsubscribe()}}class u{constructor(){this.chain=[],this.flow={isBreak:!1,isAvailable:!1,payload:null},this.response={isOK:!1,payload:void 0}}get isEmpty(){return!this.chain.length}push(s){return this.chain.push(s),this}filter(s){return this.push((r=>s(r.payload)&&(r.isAvailable=!0)))}pushFilters(s){if(!Array.isArray(s))return this;for(let r=0;r<s.length;r++)this.filter(s[r]);return this}switch(){return new a(this)}processChain(s){const r=this.chain,e=this.flow,t=this.response;t.isOK=!1,t.payload=void 0,e.payload=s,e.isBreak=!1;try{for(let s=0;s<r.length;s++){if(e.isAvailable=!1,r[s](e),!e.isAvailable)return t;if(e.isBreak)break}}catch(s){return this.errHandler?this.errHandler(s,"Filter.processChain ERROR:"):console.log("Filter.processChain ERROR:",s),t}return t.isOK=!0,t.payload=e.payload,t}addErrorHandler(s){this.errHandler=s}}class a extends i{}class o{constructor(s){this.value=s,this.subs=[],this.stop=!0,this.killed=!1,this.process=!1,this.trash=[],this.filters=new u}addFilter(s){return s&&this.filters.addErrorHandler(s),this.filters}disable(){this.stop=!1}enable(){this.stop=!0}get isEnable(){return this.stop}next(s){if(!this.killed&&this.stop&&(this.filters.isEmpty||this.filters.processChain(s).isOK)){this.process=!0,this.value=s;for(let r=0;r<this.subs.length;r++)this.subs[r].send(s);this.process=!1,this.trash.length&&this.clearTrash()}}stream(s){if(!this.killed&&this.stop)for(let r=0;r<s.length;r++)this.next(s[r])}clearTrash(){const s=this.trash.length;for(let r=0;r<s;r++)this.unSubscribe(this.trash[r]);this.trash.length=0}unSubscribe(s){this.killed||(this.process&&s?this.trash.push(s):this.subs&&e(this.subs,s))}destroy(){this.value=null,this.unsubscribeAll(),this.subs=null,this.killed=!0}unsubscribeAll(){this.killed||(this.subs.length=0)}getValue(){if(!this.killed)return this.value}size(){return this.killed?0:this.subs.length}subscribe(s,r){if(!this.isListener(s))return;const e=new l(this,!1);return this.addObserver(e,s,r),e}addObserver(s,r,e){s.subscribe(r,e),this.subs.push(s)}isListener(s){return!this.killed&&!!s}pipe(){if(this.killed)return;const s=new l(this,!0);return this.subs.push(s),s}get isDestroyed(){return this.killed}}class c extends l{constructor(s,r){super(s,r)}get order(){return this._order}set order(s){!this.observer||this.observer&&this.observer.isDestroyed?this._order=void 0:(this._order=s,this.observer.sortByOrder())}subscribe(s,r){return super.subscribe(s,r),this}setOnce(){return super.setOnce()}}const d=window;d.Observable=o,d.Collector=class{constructor(){this.arr=[],this.killed=!1}collect(...s){this.killed||this.arr.push(...s)}unsubscribe(s){this.killed||(s?.unsubscribe(),e(this.arr,s))}unsubscribeAll(){if(!this.killed)for(;this.arr.length>0;)this.unsubscribe(this.arr.pop())}size(){return this.killed?0:this.arr.length}destroy(){this.unsubscribeAll(),this.arr.length=0,this.arr=0,this.killed=!0}get isDestroyed(){return this.killed}},d.OrderedObservable=class extends o{constructor(){super(...arguments),this.sortDirection=s}setAscendingSort(){return this.sortDirection=s,this.sortByOrder()}setDescendingSort(){return this.sortDirection=r,this.sortByOrder()}sortByOrder(){return!this.killed&&(this.subs.sort(this.sortDirection),!0)}subscribe(s,r){if(!this.isListener(s))return;const e=new c(this,!1);return this.addObserver(e,s,r),e}pipe(){if(this.killed)return;const s=new c(this,!0);return this.subs.push(s),s}unSubscribe(s){this.killed||(this.process&&s?this.trash.push(s):this.subs&&function(s,r){const e=s.indexOf(r);-1!==e&&s.splice(e,1)}(this.subs,s))}}})();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ICollector, ISubscriptionLike } from "./Types";
|
|
2
2
|
export declare class Collector implements ICollector {
|
|
3
|
-
protected
|
|
4
|
-
private
|
|
3
|
+
protected arr: ISubscriptionLike[];
|
|
4
|
+
private killed;
|
|
5
5
|
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
6
6
|
unsubscribe(subscriptionLike: ISubscriptionLike | undefined): void;
|
|
7
7
|
unsubscribeAll(): void | null;
|
package/src/outLib/Collector.js
CHANGED
|
@@ -3,37 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Collector = void 0;
|
|
4
4
|
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
5
|
class Collector {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
arr = [];
|
|
7
|
+
killed = false;
|
|
8
8
|
collect(...subscriptionLikeList) {
|
|
9
|
-
if (!this.
|
|
10
|
-
this.
|
|
9
|
+
if (!this.killed)
|
|
10
|
+
this.arr.push(...subscriptionLikeList);
|
|
11
11
|
}
|
|
12
12
|
unsubscribe(subscriptionLike) {
|
|
13
|
-
if (this.
|
|
13
|
+
if (this.killed)
|
|
14
14
|
return;
|
|
15
15
|
subscriptionLike?.unsubscribe();
|
|
16
|
-
(0, FunctionLibs_1.quickDeleteFromArray)(this.
|
|
16
|
+
(0, FunctionLibs_1.quickDeleteFromArray)(this.arr, subscriptionLike);
|
|
17
17
|
}
|
|
18
18
|
unsubscribeAll() {
|
|
19
|
-
if (this.
|
|
19
|
+
if (this.killed)
|
|
20
20
|
return;
|
|
21
|
-
while (this.
|
|
22
|
-
this.unsubscribe(this.
|
|
21
|
+
while (this.arr.length > 0)
|
|
22
|
+
this.unsubscribe(this.arr.pop());
|
|
23
23
|
}
|
|
24
24
|
size() {
|
|
25
|
-
if (this.
|
|
25
|
+
if (this.killed)
|
|
26
26
|
return 0;
|
|
27
|
-
return this.
|
|
27
|
+
return this.arr.length;
|
|
28
28
|
}
|
|
29
29
|
destroy() {
|
|
30
30
|
this.unsubscribeAll();
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
31
|
+
this.arr.length = 0;
|
|
32
|
+
this.arr = 0;
|
|
33
|
+
this.killed = true;
|
|
34
34
|
}
|
|
35
35
|
get isDestroyed() {
|
|
36
|
-
return this.
|
|
36
|
+
return this.killed;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.Collector = Collector;
|
|
@@ -15,10 +15,7 @@ class FilterCollection {
|
|
|
15
15
|
return this;
|
|
16
16
|
}
|
|
17
17
|
filter(condition) {
|
|
18
|
-
return this.push((data) =>
|
|
19
|
-
if (condition(data.payload))
|
|
20
|
-
data.isAvailable = true;
|
|
21
|
-
});
|
|
18
|
+
return this.push((data) => condition(data.payload) && (data.isAvailable = true));
|
|
22
19
|
}
|
|
23
20
|
pushFilters(conditions) {
|
|
24
21
|
if (!Array.isArray(conditions))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IListener, ISubscribeGroup, ISubscribeObject } from "./Types";
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
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>(listener: ISubscribeGroup<T>): IListener<T>;
|
|
@@ -1,55 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getListener = exports.quickDeleteFromArray = exports.deleteFromArray = exports.sortDescending = exports.sortAscending = void 0;
|
|
4
|
-
|
|
4
|
+
function sortAscending(a, b) {
|
|
5
5
|
if (a.order > b.order)
|
|
6
6
|
return 1;
|
|
7
7
|
if (a.order < b.order)
|
|
8
8
|
return -1;
|
|
9
9
|
return 0;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
11
|
exports.sortAscending = sortAscending;
|
|
12
|
-
|
|
12
|
+
function sortDescending(a, b) {
|
|
13
13
|
if (a.order > b.order)
|
|
14
14
|
return -1;
|
|
15
15
|
if (a.order < b.order)
|
|
16
16
|
return 1;
|
|
17
17
|
return 0;
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
exports.sortDescending = sortDescending;
|
|
20
|
-
|
|
20
|
+
function deleteFromArray(arr, component) {
|
|
21
21
|
const index = arr.indexOf(component);
|
|
22
22
|
if (index === -1)
|
|
23
23
|
return false;
|
|
24
24
|
arr.splice(index, 1);
|
|
25
25
|
return true;
|
|
26
|
-
}
|
|
26
|
+
}
|
|
27
27
|
exports.deleteFromArray = deleteFromArray;
|
|
28
|
-
|
|
28
|
+
function quickDeleteFromArray(arr, component) {
|
|
29
29
|
const index = arr.indexOf(component);
|
|
30
30
|
if (index === -1)
|
|
31
31
|
return false;
|
|
32
32
|
arr[index] = arr[arr.length - 1];
|
|
33
33
|
arr.length = arr.length - 1;
|
|
34
34
|
return true;
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
exports.quickDeleteFromArray = quickDeleteFromArray;
|
|
37
|
-
|
|
37
|
+
function getListener(listener) {
|
|
38
38
|
if (Array.isArray(listener)) {
|
|
39
39
|
const group = [];
|
|
40
|
-
for (let i = 0; i < listener.length; i++)
|
|
40
|
+
for (let i = 0; i < listener.length; i++)
|
|
41
41
|
group.push(wrapListener(listener[i]));
|
|
42
|
-
}
|
|
43
42
|
return (data) => {
|
|
44
43
|
for (let i = 0; i < group.length; i++)
|
|
45
44
|
group[i](data);
|
|
46
45
|
};
|
|
47
46
|
}
|
|
48
47
|
return wrapListener(listener);
|
|
49
|
-
}
|
|
48
|
+
}
|
|
50
49
|
exports.getListener = getListener;
|
|
51
|
-
|
|
50
|
+
function wrapListener(listener) {
|
|
52
51
|
if ("next" in listener)
|
|
53
52
|
return (value) => listener.next(value);
|
|
54
53
|
return listener;
|
|
55
|
-
}
|
|
54
|
+
}
|
|
@@ -2,10 +2,10 @@ import { IAddFilter, IErrorCallback, IFilterSetup, IObserver, ISetup, IStream, I
|
|
|
2
2
|
import { SubscribeObject } from "./SubscribeObject";
|
|
3
3
|
export declare class Observable<T> implements IObserver<T>, IStream<T>, IAddFilter<T> {
|
|
4
4
|
private value;
|
|
5
|
-
protected
|
|
6
|
-
private
|
|
7
|
-
protected
|
|
8
|
-
protected
|
|
5
|
+
protected subs: ISubscribeObject<T>[];
|
|
6
|
+
private enabled;
|
|
7
|
+
protected killed: boolean;
|
|
8
|
+
protected process: boolean;
|
|
9
9
|
protected trash: ISubscriptionLike[];
|
|
10
10
|
private filters;
|
|
11
11
|
constructor(value: T);
|
|
@@ -15,7 +15,7 @@ export declare class Observable<T> implements IObserver<T>, IStream<T>, IAddFilt
|
|
|
15
15
|
get isEnable(): boolean;
|
|
16
16
|
next(value: T): void;
|
|
17
17
|
stream(values: T[]): void;
|
|
18
|
-
private
|
|
18
|
+
private clearTrash;
|
|
19
19
|
unSubscribe(listener: ISubscriptionLike): void;
|
|
20
20
|
destroy(): void;
|
|
21
21
|
unsubscribeAll(): void;
|
package/src/outLib/Observable.js
CHANGED
|
@@ -6,89 +6,99 @@ const SubscribeObject_1 = require("./SubscribeObject");
|
|
|
6
6
|
const FilterCollection_1 = require("./FilterCollection");
|
|
7
7
|
class Observable {
|
|
8
8
|
value;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
subs = [];
|
|
10
|
+
enabled = true;
|
|
11
|
+
killed = false;
|
|
12
|
+
process = false;
|
|
13
13
|
trash = [];
|
|
14
14
|
filters = new FilterCollection_1.FilterCollection();
|
|
15
15
|
constructor(value) {
|
|
16
16
|
this.value = value;
|
|
17
17
|
}
|
|
18
18
|
addFilter(errorHandler) {
|
|
19
|
-
if (errorHandler)
|
|
19
|
+
if (errorHandler)
|
|
20
20
|
this.filters.addErrorHandler(errorHandler);
|
|
21
|
-
}
|
|
22
21
|
return this.filters;
|
|
23
22
|
}
|
|
24
23
|
disable() {
|
|
25
|
-
this.
|
|
24
|
+
this.enabled = false;
|
|
26
25
|
}
|
|
27
26
|
enable() {
|
|
28
|
-
this.
|
|
27
|
+
this.enabled = true;
|
|
29
28
|
}
|
|
30
29
|
get isEnable() {
|
|
31
|
-
return this.
|
|
30
|
+
return this.enabled;
|
|
32
31
|
}
|
|
33
32
|
next(value) {
|
|
34
|
-
if (this.
|
|
33
|
+
if (this.killed)
|
|
35
34
|
return;
|
|
36
|
-
if (!this.
|
|
35
|
+
if (!this.enabled)
|
|
37
36
|
return;
|
|
38
|
-
if (!this.filters.isEmpty)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
this.isProcess = true;
|
|
37
|
+
if (!this.filters.isEmpty && !this.filters.processChain(value).isOK)
|
|
38
|
+
return;
|
|
39
|
+
this.process = true;
|
|
43
40
|
this.value = value;
|
|
44
|
-
for (let i = 0; i < this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.trash.length && this.
|
|
41
|
+
for (let i = 0; i < this.subs.length; i++)
|
|
42
|
+
this.subs[i].send(value);
|
|
43
|
+
this.process = false;
|
|
44
|
+
this.trash.length && this.clearTrash();
|
|
48
45
|
}
|
|
49
46
|
stream(values) {
|
|
50
|
-
if (this.
|
|
47
|
+
if (this.killed)
|
|
51
48
|
return;
|
|
52
|
-
if (!this.
|
|
49
|
+
if (!this.enabled)
|
|
53
50
|
return;
|
|
54
51
|
for (let i = 0; i < values.length; i++)
|
|
55
52
|
this.next(values[i]);
|
|
56
53
|
}
|
|
57
|
-
|
|
54
|
+
clearTrash() {
|
|
58
55
|
const length = this.trash.length;
|
|
59
56
|
for (let i = 0; i < length; i++)
|
|
60
57
|
this.unSubscribe(this.trash[i]);
|
|
61
58
|
this.trash.length = 0;
|
|
62
59
|
}
|
|
63
60
|
unSubscribe(listener) {
|
|
64
|
-
if (this.
|
|
61
|
+
if (this.killed)
|
|
65
62
|
return;
|
|
66
|
-
if (this.
|
|
63
|
+
if (this.process && listener) {
|
|
67
64
|
this.trash.push(listener);
|
|
68
65
|
return;
|
|
69
66
|
}
|
|
70
|
-
this.
|
|
67
|
+
this.subs && !(0, FunctionLibs_1.quickDeleteFromArray)(this.subs, listener);
|
|
71
68
|
}
|
|
72
69
|
destroy() {
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
70
|
+
if (this.killed)
|
|
71
|
+
return;
|
|
72
|
+
this.killed = true;
|
|
73
|
+
if (!this.process) {
|
|
74
|
+
this.value = null;
|
|
75
|
+
this.unsubscribeAll();
|
|
76
|
+
this.subs.length = 0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const timer = setInterval(() => {
|
|
80
|
+
if (this.process)
|
|
81
|
+
return;
|
|
82
|
+
clearInterval(timer);
|
|
83
|
+
this.value = null;
|
|
84
|
+
this.unsubscribeAll();
|
|
85
|
+
this.subs.length = 0;
|
|
86
|
+
}, 10);
|
|
77
87
|
}
|
|
78
88
|
unsubscribeAll() {
|
|
79
|
-
if (this.
|
|
89
|
+
if (this.killed)
|
|
80
90
|
return;
|
|
81
|
-
this.
|
|
91
|
+
this.subs.length = 0;
|
|
82
92
|
}
|
|
83
93
|
getValue() {
|
|
84
|
-
if (this.
|
|
94
|
+
if (this.killed)
|
|
85
95
|
return undefined;
|
|
86
96
|
return this.value;
|
|
87
97
|
}
|
|
88
98
|
size() {
|
|
89
|
-
if (this.
|
|
99
|
+
if (this.killed)
|
|
90
100
|
return 0;
|
|
91
|
-
return this.
|
|
101
|
+
return this.subs.length;
|
|
92
102
|
}
|
|
93
103
|
subscribe(observer, errorHandler) {
|
|
94
104
|
if (!this.isListener(observer))
|
|
@@ -99,22 +109,22 @@ class Observable {
|
|
|
99
109
|
}
|
|
100
110
|
addObserver(subscribeObject, observer, errorHandler) {
|
|
101
111
|
subscribeObject.subscribe(observer, errorHandler);
|
|
102
|
-
this.
|
|
112
|
+
this.subs.push(subscribeObject);
|
|
103
113
|
}
|
|
104
114
|
isListener(listener) {
|
|
105
|
-
if (this.
|
|
115
|
+
if (this.killed)
|
|
106
116
|
return false;
|
|
107
117
|
return !!listener;
|
|
108
118
|
}
|
|
109
119
|
pipe() {
|
|
110
|
-
if (this.
|
|
120
|
+
if (this.killed)
|
|
111
121
|
return undefined;
|
|
112
122
|
const subscribeObject = new SubscribeObject_1.SubscribeObject(this, true);
|
|
113
|
-
this.
|
|
123
|
+
this.subs.push(subscribeObject);
|
|
114
124
|
return subscribeObject;
|
|
115
125
|
}
|
|
116
126
|
get isDestroyed() {
|
|
117
|
-
return this.
|
|
127
|
+
return this.killed;
|
|
118
128
|
}
|
|
119
129
|
}
|
|
120
130
|
exports.Observable = Observable;
|
|
@@ -15,9 +15,9 @@ class OrderedObservable extends Observable_1.Observable {
|
|
|
15
15
|
return this.sortByOrder();
|
|
16
16
|
}
|
|
17
17
|
sortByOrder() {
|
|
18
|
-
if (this.
|
|
18
|
+
if (this.killed)
|
|
19
19
|
return false;
|
|
20
|
-
this.
|
|
20
|
+
this.subs.sort(this.sortDirection);
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
23
|
subscribe(listener, errorHandler) {
|
|
@@ -28,20 +28,20 @@ class OrderedObservable extends Observable_1.Observable {
|
|
|
28
28
|
return subscribeObject;
|
|
29
29
|
}
|
|
30
30
|
pipe() {
|
|
31
|
-
if (this.
|
|
31
|
+
if (this.killed)
|
|
32
32
|
return undefined;
|
|
33
33
|
const subscribeObject = new OrderedSubscribeObject_1.OrderedSubscribeObject(this, true);
|
|
34
|
-
this.
|
|
34
|
+
this.subs.push(subscribeObject);
|
|
35
35
|
return subscribeObject;
|
|
36
36
|
}
|
|
37
37
|
unSubscribe(listener) {
|
|
38
|
-
if (this.
|
|
38
|
+
if (this.killed)
|
|
39
39
|
return;
|
|
40
|
-
if (this.
|
|
40
|
+
if (this.process && listener) {
|
|
41
41
|
this.trash.push(listener);
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
this.
|
|
44
|
+
this.subs && !(0, FunctionLibs_1.deleteFromArray)(this.subs, listener);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
exports.OrderedObservable = OrderedObservable;
|
|
@@ -10,13 +10,13 @@ class OrderedSubscribeObject extends SubscribeObject_1.SubscribeObject {
|
|
|
10
10
|
return this._order;
|
|
11
11
|
}
|
|
12
12
|
set order(value) {
|
|
13
|
-
if (!this.
|
|
14
|
-
(this.
|
|
13
|
+
if (!this.observer ||
|
|
14
|
+
(this.observer && this.observer.isDestroyed)) {
|
|
15
15
|
this._order = undefined;
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
this._order = value;
|
|
19
|
-
this.
|
|
19
|
+
this.observer.sortByOrder();
|
|
20
20
|
}
|
|
21
21
|
subscribe(observer, errorHandler) {
|
|
22
22
|
super.subscribe(observer, errorHandler);
|
package/src/outLib/Pipe.js
CHANGED
|
@@ -23,10 +23,7 @@ class Pipe {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
refine(condition) {
|
|
26
|
-
return this.push((data) =>
|
|
27
|
-
if (condition(data.payload))
|
|
28
|
-
data.isAvailable = true;
|
|
29
|
-
});
|
|
26
|
+
return this.push((data) => condition(data.payload) && (data.isAvailable = true));
|
|
30
27
|
}
|
|
31
28
|
pushRefiners(conditions) {
|
|
32
29
|
if (!Array.isArray(conditions))
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IErrorCallback, IListener, IObserver, ISubscribeGroup, ISubscribeObject, ISubscriptionLike } from "./Types";
|
|
2
2
|
import { Pipe } from "./Pipe";
|
|
3
3
|
export declare class SubscribeObject<T> extends Pipe<T> implements ISubscribeObject<T> {
|
|
4
|
-
|
|
4
|
+
observer: IObserver<T> | undefined;
|
|
5
5
|
listener: IListener<T> | undefined;
|
|
6
6
|
errorHandler: IErrorCallback;
|
|
7
7
|
_order: number;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
paused: boolean;
|
|
9
|
+
piped: boolean;
|
|
10
10
|
constructor(observable?: IObserver<T>, isPipe?: boolean);
|
|
11
11
|
subscribe(observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike;
|
|
12
12
|
unsubscribe(): void;
|
|
@@ -4,18 +4,18 @@ exports.SubscribeObject = void 0;
|
|
|
4
4
|
const Pipe_1 = require("./Pipe");
|
|
5
5
|
const FunctionLibs_1 = require("./FunctionLibs");
|
|
6
6
|
class SubscribeObject extends Pipe_1.Pipe {
|
|
7
|
-
|
|
7
|
+
observer;
|
|
8
8
|
listener;
|
|
9
9
|
errorHandler = (errorData, errorMessage) => {
|
|
10
10
|
console.log(`(Unit of SubscribeObject).send(${errorData}) ERROR:`, errorMessage);
|
|
11
11
|
};
|
|
12
12
|
_order = 0;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
paused = false;
|
|
14
|
+
piped = false;
|
|
15
15
|
constructor(observable, isPipe) {
|
|
16
16
|
super();
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this.observer = observable;
|
|
18
|
+
this.piped = !!isPipe;
|
|
19
19
|
}
|
|
20
20
|
subscribe(observer, errorHandler) {
|
|
21
21
|
this.listener = (0, FunctionLibs_1.getListener)(observer);
|
|
@@ -23,10 +23,10 @@ class SubscribeObject extends Pipe_1.Pipe {
|
|
|
23
23
|
return this;
|
|
24
24
|
}
|
|
25
25
|
unsubscribe() {
|
|
26
|
-
if (!this.
|
|
26
|
+
if (!this.observer)
|
|
27
27
|
return;
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
28
|
+
this.observer.unSubscribe(this);
|
|
29
|
+
this.observer = null;
|
|
30
30
|
this.listener = null;
|
|
31
31
|
this.chain.length = 0;
|
|
32
32
|
}
|
|
@@ -41,10 +41,10 @@ class SubscribeObject extends Pipe_1.Pipe {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
resume() {
|
|
44
|
-
this.
|
|
44
|
+
this.paused = false;
|
|
45
45
|
}
|
|
46
46
|
pause() {
|
|
47
|
-
this.
|
|
47
|
+
this.paused = true;
|
|
48
48
|
}
|
|
49
49
|
get order() {
|
|
50
50
|
return this._order;
|
|
@@ -56,11 +56,11 @@ class SubscribeObject extends Pipe_1.Pipe {
|
|
|
56
56
|
const listener = this.listener;
|
|
57
57
|
if (!listener)
|
|
58
58
|
return this.unsubscribe();
|
|
59
|
-
if (!this.
|
|
59
|
+
if (!this.observer)
|
|
60
60
|
return;
|
|
61
|
-
if (this.
|
|
61
|
+
if (this.paused)
|
|
62
62
|
return;
|
|
63
|
-
if (!this.
|
|
63
|
+
if (!this.piped)
|
|
64
64
|
return listener(value);
|
|
65
65
|
return this.processChain(listener);
|
|
66
66
|
}
|