evg_observable 2.14.61 → 2.15.0

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.
Files changed (44) hide show
  1. package/BREAKING_CHANGES.md +70 -0
  2. package/package.json +12 -6
  3. package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.d.ts +37 -0
  4. package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.js +61 -0
  5. package/src/outLib/src/Libraries/Observables/Collector.d.ts +56 -0
  6. package/src/outLib/src/Libraries/Observables/Collector.js +86 -0
  7. package/src/outLib/src/Libraries/Observables/FilterCollection.d.ts +70 -0
  8. package/src/outLib/src/Libraries/Observables/FilterCollection.js +122 -0
  9. package/src/outLib/src/Libraries/Observables/FunctionLibs.d.ts +48 -0
  10. package/src/outLib/src/Libraries/Observables/FunctionLibs.js +101 -0
  11. package/src/outLib/src/Libraries/Observables/Observable.d.ts +160 -0
  12. package/src/outLib/src/Libraries/Observables/Observable.js +268 -0
  13. package/src/outLib/src/Libraries/Observables/OrderedObservable.d.ts +70 -0
  14. package/src/outLib/src/Libraries/Observables/OrderedObservable.js +106 -0
  15. package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.d.ts +53 -0
  16. package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.js +72 -0
  17. package/src/outLib/src/Libraries/Observables/Pipe.d.ts +108 -0
  18. package/src/outLib/src/Libraries/Observables/Pipe.js +161 -0
  19. package/src/outLib/src/Libraries/Observables/SubscribeObject.d.ts +83 -0
  20. package/src/outLib/src/Libraries/Observables/SubscribeObject.js +139 -0
  21. package/src/outLib/src/Libraries/Observables/Types.d.ts +727 -0
  22. package/src/outLib/{index.d.ts → src/Libraries/Observables/index.d.ts} +1 -0
  23. package/repo/evg_observable.js +0 -1
  24. package/src/outLib/AbstractSwitchCase.d.ts +0 -8
  25. package/src/outLib/AbstractSwitchCase.js +0 -32
  26. package/src/outLib/Collector.d.ts +0 -11
  27. package/src/outLib/Collector.js +0 -39
  28. package/src/outLib/FilterCollection.d.ts +0 -17
  29. package/src/outLib/FilterCollection.js +0 -68
  30. package/src/outLib/FunctionLibs.d.ts +0 -6
  31. package/src/outLib/FunctionLibs.js +0 -54
  32. package/src/outLib/Observable.d.ts +0 -29
  33. package/src/outLib/Observable.js +0 -130
  34. package/src/outLib/OrderedObservable.d.ts +0 -11
  35. package/src/outLib/OrderedObservable.js +0 -47
  36. package/src/outLib/OrderedSubscribeObject.d.ts +0 -10
  37. package/src/outLib/OrderedSubscribeObject.js +0 -29
  38. package/src/outLib/Pipe.d.ts +0 -20
  39. package/src/outLib/Pipe.js +0 -79
  40. package/src/outLib/SubscribeObject.d.ts +0 -19
  41. package/src/outLib/SubscribeObject.js +0 -68
  42. package/src/outLib/Types.d.ts +0 -165
  43. /package/src/outLib/{Types.js → src/Libraries/Observables/Types.js} +0 -0
  44. /package/src/outLib/{index.js → src/Libraries/Observables/index.js} +0 -0
@@ -3,3 +3,4 @@ export { OrderedObservable } from './OrderedObservable';
3
3
  export { Collector } from './Collector';
4
4
  export { deleteFromArray } from './FunctionLibs';
5
5
  export { quickDeleteFromArray } from './FunctionLibs';
6
+ export { ISubscriptionLike, IOrderedSubscriptionLike } from './Types';
@@ -1 +0,0 @@
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,8 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
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;
@@ -1,11 +0,0 @@
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
- }
@@ -1,39 +0,0 @@
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
- while (this.arr.length > 0)
22
- this.unsubscribe(this.arr.pop());
23
- }
24
- size() {
25
- if (this.killed)
26
- return 0;
27
- return this.arr.length;
28
- }
29
- destroy() {
30
- this.unsubscribeAll();
31
- this.arr.length = 0;
32
- this.arr = 0;
33
- this.killed = true;
34
- }
35
- get isDestroyed() {
36
- return this.killed;
37
- }
38
- }
39
- exports.Collector = Collector;
@@ -1,17 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- for (let i = 0; i < chain.length; i++) {
40
- data.isAvailable = false;
41
- chain[i](data);
42
- if (!data.isAvailable)
43
- return response;
44
- if (data.isBreak)
45
- break;
46
- }
47
- }
48
- catch (err) {
49
- if (this.errHandler) {
50
- this.errHandler(err, "Filter.processChain ERROR:");
51
- }
52
- else {
53
- console.log("Filter.processChain ERROR:", err);
54
- }
55
- return response;
56
- }
57
- response.isOK = true;
58
- response.payload = data.payload;
59
- return response;
60
- }
61
- addErrorHandler(errorHandler) {
62
- this.errHandler = errorHandler;
63
- }
64
- }
65
- exports.FilterCollection = FilterCollection;
66
- class FilterSwitchCase extends AbstractSwitchCase_1.SwitchCase {
67
- }
68
- exports.FilterSwitchCase = FilterSwitchCase;
@@ -1,6 +0,0 @@
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>(listener: ISubscribeGroup<T>): IListener<T>;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getListener = exports.quickDeleteFromArray = exports.deleteFromArray = exports.sortDescending = exports.sortAscending = void 0;
4
- function sortAscending(a, b) {
5
- if (a.order > b.order)
6
- return 1;
7
- if (a.order < b.order)
8
- return -1;
9
- return 0;
10
- }
11
- exports.sortAscending = sortAscending;
12
- function sortDescending(a, b) {
13
- if (a.order > b.order)
14
- return -1;
15
- if (a.order < b.order)
16
- return 1;
17
- return 0;
18
- }
19
- exports.sortDescending = sortDescending;
20
- function deleteFromArray(arr, component) {
21
- const index = arr.indexOf(component);
22
- if (index === -1)
23
- return false;
24
- arr.splice(index, 1);
25
- return true;
26
- }
27
- exports.deleteFromArray = deleteFromArray;
28
- function quickDeleteFromArray(arr, component) {
29
- const index = arr.indexOf(component);
30
- if (index === -1)
31
- return false;
32
- arr[index] = arr[arr.length - 1];
33
- arr.length = arr.length - 1;
34
- return true;
35
- }
36
- exports.quickDeleteFromArray = quickDeleteFromArray;
37
- function getListener(listener) {
38
- if (Array.isArray(listener)) {
39
- const group = [];
40
- for (let i = 0; i < listener.length; i++)
41
- group.push(wrapListener(listener[i]));
42
- return (data) => {
43
- for (let i = 0; i < group.length; i++)
44
- group[i](data);
45
- };
46
- }
47
- return wrapListener(listener);
48
- }
49
- exports.getListener = getListener;
50
- function wrapListener(listener) {
51
- if ("next" in listener)
52
- return (value) => listener.next(value);
53
- return listener;
54
- }
@@ -1,29 +0,0 @@
1
- import { IAddFilter, IErrorCallback, IFilterSetup, IObserver, ISetup, IStream, ISubscribeGroup, ISubscribeObject, ISubscriptionLike } from "./Types";
2
- import { SubscribeObject } from "./SubscribeObject";
3
- export declare class Observable<T> implements IObserver<T>, IStream<T>, IAddFilter<T> {
4
- private value;
5
- protected subs: ISubscribeObject<T>[];
6
- private enabled;
7
- protected killed: boolean;
8
- protected process: boolean;
9
- protected trash: ISubscriptionLike[];
10
- private filters;
11
- constructor(value: T);
12
- addFilter(errorHandler?: IErrorCallback): IFilterSetup<T>;
13
- disable(): void;
14
- enable(): void;
15
- get isEnable(): boolean;
16
- next(value: T): void;
17
- stream(values: T[]): void;
18
- private clearTrash;
19
- unSubscribe(listener: ISubscriptionLike): void;
20
- destroy(): void;
21
- unsubscribeAll(): void;
22
- getValue(): T | undefined;
23
- size(): number;
24
- subscribe(observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
25
- protected addObserver(subscribeObject: SubscribeObject<T>, observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): void;
26
- protected isListener(listener: ISubscribeGroup<T>): boolean;
27
- pipe(): ISetup<T> | undefined;
28
- get isDestroyed(): boolean;
29
- }
@@ -1,130 +0,0 @@
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
- value;
9
- subs = [];
10
- enabled = true;
11
- killed = false;
12
- process = false;
13
- trash = [];
14
- filters = new FilterCollection_1.FilterCollection();
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.filters.isEmpty && !this.filters.processChain(value).isOK)
38
- return;
39
- this.process = true;
40
- this.value = value;
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();
45
- }
46
- stream(values) {
47
- if (this.killed)
48
- return;
49
- if (!this.enabled)
50
- return;
51
- for (let i = 0; i < values.length; i++)
52
- this.next(values[i]);
53
- }
54
- clearTrash() {
55
- const length = this.trash.length;
56
- for (let i = 0; i < length; i++)
57
- this.unSubscribe(this.trash[i]);
58
- this.trash.length = 0;
59
- }
60
- unSubscribe(listener) {
61
- if (this.killed)
62
- return;
63
- if (this.process && listener) {
64
- this.trash.push(listener);
65
- return;
66
- }
67
- this.subs && !(0, FunctionLibs_1.quickDeleteFromArray)(this.subs, listener);
68
- }
69
- destroy() {
70
- if (this.killed)
71
- return;
72
- this.killed = true;
73
- if (!this.process) {
74
- this.value = null;
75
- this.subs.length = 0;
76
- return;
77
- }
78
- const timer = setInterval(() => {
79
- if (this.process)
80
- return;
81
- clearInterval(timer);
82
- this.value = null;
83
- this.subs.length = 0;
84
- }, 10);
85
- }
86
- unsubscribeAll() {
87
- if (this.killed)
88
- return;
89
- this.subs.length = 0;
90
- }
91
- getValue() {
92
- if (this.killed)
93
- return undefined;
94
- return this.value;
95
- }
96
- size() {
97
- if (this.killed)
98
- return 0;
99
- return this.subs.length;
100
- }
101
- subscribe(observer, errorHandler) {
102
- if (this.killed)
103
- return undefined;
104
- if (!this.isListener(observer))
105
- return undefined;
106
- const subscribeObject = new SubscribeObject_1.SubscribeObject(this, false);
107
- this.addObserver(subscribeObject, observer, errorHandler);
108
- return subscribeObject;
109
- }
110
- addObserver(subscribeObject, observer, errorHandler) {
111
- subscribeObject.subscribe(observer, errorHandler);
112
- this.subs.push(subscribeObject);
113
- }
114
- isListener(listener) {
115
- if (this.killed)
116
- return false;
117
- return !!listener;
118
- }
119
- pipe() {
120
- if (this.killed)
121
- return undefined;
122
- const subscribeObject = new SubscribeObject_1.SubscribeObject(this, true);
123
- this.subs.push(subscribeObject);
124
- return subscribeObject;
125
- }
126
- get isDestroyed() {
127
- return this.killed;
128
- }
129
- }
130
- exports.Observable = Observable;
@@ -1,11 +0,0 @@
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
- }
@@ -1,47 +0,0 @@
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.deleteFromArray)(this.subs, listener);
45
- }
46
- }
47
- exports.OrderedObservable = OrderedObservable;
@@ -1,10 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
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;
@@ -1,20 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
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
- for (let i = 0; i < chain.length; i++) {
60
- data.isUnsubscribe = false;
61
- data.isAvailable = false;
62
- chain[i](data);
63
- if (data.isUnsubscribe)
64
- return this.unsubscribe();
65
- if (!data.isAvailable)
66
- return;
67
- if (data.isBreak)
68
- break;
69
- }
70
- return listener(data.payload);
71
- }
72
- }
73
- exports.Pipe = Pipe;
74
- class PipeSwitchCase extends AbstractSwitchCase_1.SwitchCase {
75
- subscribe(listener, errorHandler) {
76
- return this.pipe.subscribe(listener, errorHandler);
77
- }
78
- }
79
- exports.PipeSwitchCase = PipeSwitchCase;
@@ -1,19 +0,0 @@
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
- processValue<T>(value: T): void;
19
- }