evg_observable 1.11.50 → 1.11.51
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/README.md +34 -66
- package/package.json +1 -1
- package/repo/evg_observable.js +1 -1
- package/src/outLib/Pipe.d.ts +1 -0
- package/src/outLib/Pipe.js +3 -0
- package/src/outLib/Types.d.ts +8 -6
package/README.md
CHANGED
|
@@ -172,44 +172,7 @@ observable$.next('Next2 typed data');
|
|
|
172
172
|
// subscriber1 is automatically unsubscribed after first usage
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
### pipe().
|
|
176
|
-
|
|
177
|
-
Observable will send a value to the subscriber as long as the condition is positive, on the first negative result, the
|
|
178
|
-
subscriber will unsubscribe.
|
|
179
|
-
|
|
180
|
-
```ts
|
|
181
|
-
import {Observable} from "evg_observable/src/outLib/Observable";
|
|
182
|
-
|
|
183
|
-
const observable$ = new Observable('Some typed data (not only string)');
|
|
184
|
-
const listener1 = (value: string) => console.log('listener1:', value);
|
|
185
|
-
const listener2 = (value: string) => console.log('listener2:', value);
|
|
186
|
-
let isPositive = true;
|
|
187
|
-
|
|
188
|
-
const subscriber1 = observable$
|
|
189
|
-
.pipe()
|
|
190
|
-
.unsubscribeByNegative(() => isPositive)
|
|
191
|
-
.subscribe(listener1);
|
|
192
|
-
const subscriber2 = observable$.subscribe(listener2);
|
|
193
|
-
|
|
194
|
-
console.log(observable$.getValue());
|
|
195
|
-
// Print to console - Some typed data (not only string)
|
|
196
|
-
|
|
197
|
-
observable$.next('Next1 typed data');
|
|
198
|
-
// Print to console - listener1: Next1 typed data
|
|
199
|
-
// Print to console - listener2: Next1 typed data
|
|
200
|
-
|
|
201
|
-
observable$.next('Next2 typed data');
|
|
202
|
-
// Print to console - listener1: Next2 typed data
|
|
203
|
-
// Print to console - listener2: Next2 typed data
|
|
204
|
-
|
|
205
|
-
isPositive = false;
|
|
206
|
-
observable$.next('Next3 typed data');
|
|
207
|
-
// Print to console - listener2: Next3 typed data
|
|
208
|
-
|
|
209
|
-
// subscriber1 is automatically unsubscribed when negative condition
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### pipe().unsubscribeByPositive(condition)
|
|
175
|
+
### pipe().unsubscribeBy(condition)
|
|
213
176
|
|
|
214
177
|
Observable will send a value to the subscriber as long as the condition is negative, on the first positive result, the
|
|
215
178
|
subscriber will unsubscribe.
|
|
@@ -217,40 +180,39 @@ subscriber will unsubscribe.
|
|
|
217
180
|
```ts
|
|
218
181
|
import {Observable} from "evg_observable/src/outLib/Observable";
|
|
219
182
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
183
|
+
type ISomeData = {
|
|
184
|
+
message: string;
|
|
185
|
+
isNeedUnsubscribe: boolean;
|
|
186
|
+
}
|
|
224
187
|
|
|
225
|
-
const
|
|
188
|
+
const observable$ = new Observable<ISomeData>({message: "some message", isNeedUnsubscribe: false});
|
|
189
|
+
const listener1 = (value: ISomeData) => console.log('listener1:', value);
|
|
190
|
+
const listener2 = (value: ISomeData) => console.log('listener2:', value);
|
|
191
|
+
|
|
192
|
+
observable$
|
|
226
193
|
.pipe()
|
|
227
|
-
.
|
|
194
|
+
.unsubscribeBy((data: ISomeData) => data.isNeedUnsubscribe)
|
|
228
195
|
.subscribe(listener1);
|
|
229
|
-
const subscriber2 = observable$.subscribe(listener2);
|
|
230
|
-
|
|
231
|
-
console.log(observable$.getValue());
|
|
232
|
-
// Print to console - Some typed data (not only string)
|
|
233
|
-
|
|
234
|
-
observable$.next('Next1 typed data');
|
|
235
|
-
// Print to console - listener1: Next1 typed data
|
|
236
|
-
// Print to console - listener2: Next1 typed data
|
|
237
196
|
|
|
238
|
-
observable
|
|
239
|
-
|
|
240
|
-
// Print to console - listener2: Next2 typed data
|
|
197
|
+
observable$
|
|
198
|
+
.subscribe(listener2);
|
|
241
199
|
|
|
242
|
-
|
|
243
|
-
observable$.next('Next3 typed data');
|
|
244
|
-
// Print to console - listener2: Next3 typed data
|
|
200
|
+
console.log(observable$.getValue());
|
|
245
201
|
|
|
246
|
-
|
|
202
|
+
observable$.next({message: "some message1", isNeedUnsubscribe: false});
|
|
203
|
+
observable$.next({message: "some message2", isNeedUnsubscribe: false});
|
|
204
|
+
observable$.next({message: "some message3", isNeedUnsubscribe: true});
|
|
205
|
+
|
|
206
|
+
// logs:
|
|
207
|
+
// { message: 'some message', isNeedUnsubscribe: false }
|
|
208
|
+
// listener1: { message: 'some message1', isNeedUnsubscribe: false }
|
|
209
|
+
// listener2: { message: 'some message1', isNeedUnsubscribe: false }
|
|
210
|
+
// listener1: { message: 'some message2', isNeedUnsubscribe: false }
|
|
211
|
+
// listener2: { message: 'some message2', isNeedUnsubscribe: false }
|
|
212
|
+
// listener2: { message: 'some message3', isNeedUnsubscribe: true }
|
|
247
213
|
```
|
|
248
214
|
|
|
249
|
-
### pipe().
|
|
250
|
-
|
|
251
|
-
Observable will send a value to the listener only if condition returns "false". There is no automatic unsubscription.
|
|
252
|
-
|
|
253
|
-
### pipe().emitByPositive(condition)
|
|
215
|
+
### pipe().refine(condition)
|
|
254
216
|
|
|
255
217
|
Observable will send a value to the listener only if condition returns "true". There is no automatic unsubscription.
|
|
256
218
|
|
|
@@ -534,7 +496,8 @@ Observable an invaluable tool for managing asynchronous events.
|
|
|
534
496
|
Built with the developer's needs in mind, EVG Observable provides a wealth of capabilities at your disposal, making
|
|
535
497
|
event handling a breeze.
|
|
536
498
|
|
|
537
|
-
Here is an advanced example of the `pipe` usage which introduces a new method called `then`. It allows transforming
|
|
499
|
+
Here is an advanced example of the `pipe` usage which introduces a new method called `then`. It allows transforming
|
|
500
|
+
payload data in the pipe chain by applying a user callback function.
|
|
538
501
|
|
|
539
502
|
Here is the syntax:
|
|
540
503
|
|
|
@@ -566,7 +529,11 @@ targetObservable$.stream([
|
|
|
566
529
|
"12345",
|
|
567
530
|
]);
|
|
568
531
|
```
|
|
569
|
-
|
|
532
|
+
|
|
533
|
+
In this example, the observable is first refined with a condition to check for a string that includes "2". This string,
|
|
534
|
+
if it passes the condition, is then transformed into its length via a then invocation. Further, this length is filtered
|
|
535
|
+
down to lengths that are greater than 4. The lengths that pass this condition are thus doubled and the resulting
|
|
536
|
+
observable is set to be a once-off observable to which a listener is subscribed. `
|
|
570
537
|
|
|
571
538
|
## Methods
|
|
572
539
|
|
|
@@ -595,6 +562,7 @@ In this example, the observable is first refined with a condition to check for a
|
|
|
595
562
|
| `.setOnce()` | pipe object | observable will send a value to the subscriber only once, and the subscriber will unsubscribe. |
|
|
596
563
|
| `.unsubscribeByNegative(*condition)` | pipe object | observable will send a value to the subscriber as long as the condition is positive, on the first negative result, the subscriber will unsubscribe |
|
|
597
564
|
| `.unsubscribeByPositive(*condition)` | pipe object | observable will send a value to the subscriber as long as the condition is negative, on the first positive result, the subscriber will unsubscribe |
|
|
565
|
+
| `.unsubscribeBy(*condition)` | pipe object | observable will send a value to the subscriber as long as the condition is negative, on the first positive result, the subscriber will unsubscribe |
|
|
598
566
|
| `.emitByNegative(*condition)` | pipe object | observable will send a value to the listener only if condition returns "false", there is no automatic unsubscription |
|
|
599
567
|
| `.emitByPositive(*condition)` | pipe object | observable will send a value to the listener only if condition returns "true", there is no automatic unsubscription |
|
|
600
568
|
| `.refine(*condition)` | pipe object | observable will send a value to the listener only if condition returns "true", there is no automatic unsubscription |
|
package/package.json
CHANGED
package/repo/evg_observable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const s=(s,e)=>s.order>e.order?1:s.order<e.order?-1:0,e=(s,e)=>s.order>e.order?-1:s.order<e.order?1:0;function i(s,e){const i=s.indexOf(e);return-1!==i&&(s[i]=s[s.length-1],s.length=s.length-1,!0)}function t(s){return"next"in s?e=>s.next(e):s}class r{constructor(){this.chainHandlers=[],this.pipeData={isBreakChain:!1,isNeedUnsubscribe:!1,isAvailable:!1,payload:null}}setOnce(){const s=this.pipeData;return this.chainHandlers.push((()=>{this.listener(s.payload),s.isNeedUnsubscribe=!0})),this}unsubscribeByNegative(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.isAvailable=!0,s(e.payload)||(e.isNeedUnsubscribe=!0)})),this}unsubscribeByPositive(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.isAvailable=!0,s(e.payload)&&(e.isNeedUnsubscribe=!0)})),this}emitByNegative(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)||(e.isAvailable=!0)})),this}emitByPositive(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}refine(s){return this.emitByPositive(s)}pushRefiners(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.emitByPositive(s[e]);return this}emitMatch(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)==e.payload&&(e.isAvailable=!0)})),this}switch(){return new n(this)}processChain(s){const e=this.chainHandlers,i=this.pipeData;for(let s=0;s<e.length;s++){if(i.isNeedUnsubscribe=!1,i.isAvailable=!1,e[s](),i.isNeedUnsubscribe)return this.unsubscribe();if(!i.isAvailable)return;if(i.isBreakChain)break}return s(i.payload)}}class n{constructor(s){this.pipe=s,this.caseCounter=s.chainHandlers.length?s.chainHandlers.length:0}subscribe(s,e){return this.pipe.subscribe(s,e)}case(s){this.caseCounter++;const e=this.caseCounter,i=this.pipe.pipeData,t=this.pipe.chainHandlers;return t.push((()=>{i.isAvailable=!0,s(i.payload)&&(i.isBreakChain=!0),e!==t.length||i.isBreakChain||(i.isAvailable=!1)})),this}pushCases(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.case(s[e]);return this}}class h extends r{constructor(s,e){super(),this.errorHandler=(s,e)=>{console.log(`(Unit of SubscribeObject).send(${s}) ERROR:`,e)},this._order=0,this.isPaused=!1,this.isPipe=!1,this.observable=s,this.isPipe=!!e}subscribe(s,e){return this.listener=function(s){if(Array.isArray(s)){const e=[];for(let i=0;i<s.length;i++)e.push(t(s[i]));return s=>{for(let i=0;i<e.length;i++)e[i](s)}}return t(s)}(s),e&&(this.errorHandler=e),this}unsubscribe(){this.observable&&(this.observable.unSubscribe(this),this.observable=null,this.listener=null,this.chainHandlers.length=0)}send(s){try{this.pipeData.payload=s,this.pipeData.isBreakChain=!1,this.processValue(s)}catch(e){this.errorHandler(s,e)}}resume(){this.isPaused=!1}pause(){this.isPaused=!0}get order(){return this._order}set order(s){this._order=s}processValue(s){const e=this.listener;return e&&this.observable?this.isPaused?void 0:this.isPipe?this.processChain(e):e(s):this.unsubscribe()}}class a{constructor(){this.chainHandlers=[],this.pipeData={isBreakChain:!1,isAvailable:!1,payload:null},this.response={isOK:!1,payload:void 0}}get isEmpty(){return!this.chainHandlers.length}filter(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}pushFilters(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.filter(s[e]);return this}switch(){return new l(this)}processChain(s){const e=this.chainHandlers,i=this.pipeData,t=this.response;t.isOK=!1,t.payload=void 0,i.payload=s,i.isBreakChain=!1;try{for(let s=0;s<e.length;s++){if(i.isAvailable=!1,e[s](),!i.isAvailable)return t;if(i.isBreakChain)break}}catch(s){return this.errorHandler?this.errorHandler(s,"Filter.processChain ERROR:"):console.log("Filter.processChain ERROR:",s),t}return t.isOK=!0,t.payload=i.payload,t}addErrorHandler(s){this.errorHandler=s}}class l{constructor(s){this.pipe=s,this.caseCounter=s.chainHandlers.length?s.chainHandlers.length:0}case(s){this.caseCounter++;const e=this.caseCounter,i=this.pipe.pipeData,t=this.pipe.chainHandlers;return t.push((()=>{i.isAvailable=!0,s(i.payload)&&(i.isBreakChain=!0),e!==t.length||i.isBreakChain||(i.isAvailable=!1)})),this}pushCases(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.case(s[e]);return this}}class o{constructor(s){this.value=s,this.listeners=[],this._isEnable=!0,this._isDestroyed=!1,this.isNextProcess=!1,this.listenersForUnsubscribe=[],this.filterCase=new a}addFilter(s){return s&&this.filterCase.addErrorHandler(s),this.filterCase}disable(){this._isEnable=!1}enable(){this._isEnable=!0}get isEnable(){return this._isEnable}next(s){if(!this._isDestroyed&&this._isEnable&&(this.filterCase.isEmpty||this.filterCase.processChain(s).isOK)){this.isNextProcess=!0,this.value=s;for(let e=0;e<this.listeners.length;e++)this.listeners[e].send(s);this.isNextProcess=!1,this.listenersForUnsubscribe.length&&this.handleListenersForUnsubscribe()}}stream(s){if(!this._isDestroyed&&this._isEnable)for(let e=0;e<s.length;e++)this.next(s[e])}handleListenersForUnsubscribe(){const s=this.listenersForUnsubscribe.length;for(let e=0;e<s;e++)this.unSubscribe(this.listenersForUnsubscribe[e]);this.listenersForUnsubscribe.length=0}unSubscribe(s){this._isDestroyed||(this.isNextProcess&&s?this.listenersForUnsubscribe.push(s):this.listeners&&i(this.listeners,s))}destroy(){this.value=null,this.unsubscribeAll(),this.listeners=null,this._isDestroyed=!0}unsubscribeAll(){this._isDestroyed||(this.listeners.length=0)}getValue(){if(!this._isDestroyed)return this.value}size(){return this._isDestroyed?0:this.listeners.length}subscribe(s,e){if(!this.isSubsValid(s))return;const i=new h(this,!1);return this.addObserver(i,s,e),i}addObserver(s,e,i){s.subscribe(e,i),this.listeners.push(s)}isSubsValid(s){return!this._isDestroyed&&!!s}pipe(){if(this._isDestroyed)return;const s=new h(this,!0);return this.listeners.push(s),s}get isDestroyed(){return this._isDestroyed}}class u extends h{constructor(s,e){super(s,e)}get order(){return this._order}set order(s){!this.observable||this.observable&&this.observable.isDestroyed?this._order=void 0:(this._order=s,this.observable.sortByOrder())}subscribe(s,e){return super.subscribe(s,e),this}setOnce(){return super.setOnce()}unsubscribeByNegative(s){return super.unsubscribeByNegative(s)}unsubscribeByPositive(s){return super.unsubscribeByPositive(s)}emitByNegative(s){return super.emitByNegative(s)}emitByPositive(s){return super.emitByPositive(s)}
|
|
1
|
+
(()=>{"use strict";const s=(s,e)=>s.order>e.order?1:s.order<e.order?-1:0,e=(s,e)=>s.order>e.order?-1:s.order<e.order?1:0;function i(s,e){const i=s.indexOf(e);return-1!==i&&(s[i]=s[s.length-1],s.length=s.length-1,!0)}function t(s){return"next"in s?e=>s.next(e):s}class r{constructor(){this.chainHandlers=[],this.pipeData={isBreakChain:!1,isNeedUnsubscribe:!1,isAvailable:!1,payload:null}}setOnce(){const s=this.pipeData;return this.chainHandlers.push((()=>{this.listener(s.payload),s.isNeedUnsubscribe=!0})),this}unsubscribeByNegative(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.isAvailable=!0,s(e.payload)||(e.isNeedUnsubscribe=!0)})),this}unsubscribeByPositive(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.isAvailable=!0,s(e.payload)&&(e.isNeedUnsubscribe=!0)})),this}emitByNegative(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)||(e.isAvailable=!0)})),this}emitByPositive(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}refine(s){return this.emitByPositive(s)}then(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.payload=s(e.payload),e.isAvailable=!0})),this}pushRefiners(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.emitByPositive(s[e]);return this}emitMatch(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)==e.payload&&(e.isAvailable=!0)})),this}switch(){return new n(this)}processChain(s){const e=this.chainHandlers,i=this.pipeData;for(let s=0;s<e.length;s++){if(i.isNeedUnsubscribe=!1,i.isAvailable=!1,e[s](),i.isNeedUnsubscribe)return this.unsubscribe();if(!i.isAvailable)return;if(i.isBreakChain)break}return s(i.payload)}}class n{constructor(s){this.pipe=s,this.caseCounter=s.chainHandlers.length?s.chainHandlers.length:0}subscribe(s,e){return this.pipe.subscribe(s,e)}case(s){this.caseCounter++;const e=this.caseCounter,i=this.pipe.pipeData,t=this.pipe.chainHandlers;return t.push((()=>{i.isAvailable=!0,s(i.payload)&&(i.isBreakChain=!0),e!==t.length||i.isBreakChain||(i.isAvailable=!1)})),this}pushCases(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.case(s[e]);return this}}class h extends r{constructor(s,e){super(),this.errorHandler=(s,e)=>{console.log(`(Unit of SubscribeObject).send(${s}) ERROR:`,e)},this._order=0,this.isPaused=!1,this.isPipe=!1,this.observable=s,this.isPipe=!!e}subscribe(s,e){return this.listener=function(s){if(Array.isArray(s)){const e=[];for(let i=0;i<s.length;i++)e.push(t(s[i]));return s=>{for(let i=0;i<e.length;i++)e[i](s)}}return t(s)}(s),e&&(this.errorHandler=e),this}unsubscribe(){this.observable&&(this.observable.unSubscribe(this),this.observable=null,this.listener=null,this.chainHandlers.length=0)}send(s){try{this.pipeData.payload=s,this.pipeData.isBreakChain=!1,this.processValue(s)}catch(e){this.errorHandler(s,e)}}resume(){this.isPaused=!1}pause(){this.isPaused=!0}get order(){return this._order}set order(s){this._order=s}processValue(s){const e=this.listener;return e&&this.observable?this.isPaused?void 0:this.isPipe?this.processChain(e):e(s):this.unsubscribe()}}class a{constructor(){this.chainHandlers=[],this.pipeData={isBreakChain:!1,isAvailable:!1,payload:null},this.response={isOK:!1,payload:void 0}}get isEmpty(){return!this.chainHandlers.length}filter(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}pushFilters(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.filter(s[e]);return this}switch(){return new l(this)}processChain(s){const e=this.chainHandlers,i=this.pipeData,t=this.response;t.isOK=!1,t.payload=void 0,i.payload=s,i.isBreakChain=!1;try{for(let s=0;s<e.length;s++){if(i.isAvailable=!1,e[s](),!i.isAvailable)return t;if(i.isBreakChain)break}}catch(s){return this.errorHandler?this.errorHandler(s,"Filter.processChain ERROR:"):console.log("Filter.processChain ERROR:",s),t}return t.isOK=!0,t.payload=i.payload,t}addErrorHandler(s){this.errorHandler=s}}class l{constructor(s){this.pipe=s,this.caseCounter=s.chainHandlers.length?s.chainHandlers.length:0}case(s){this.caseCounter++;const e=this.caseCounter,i=this.pipe.pipeData,t=this.pipe.chainHandlers;return t.push((()=>{i.isAvailable=!0,s(i.payload)&&(i.isBreakChain=!0),e!==t.length||i.isBreakChain||(i.isAvailable=!1)})),this}pushCases(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.case(s[e]);return this}}class o{constructor(s){this.value=s,this.listeners=[],this._isEnable=!0,this._isDestroyed=!1,this.isNextProcess=!1,this.listenersForUnsubscribe=[],this.filterCase=new a}addFilter(s){return s&&this.filterCase.addErrorHandler(s),this.filterCase}disable(){this._isEnable=!1}enable(){this._isEnable=!0}get isEnable(){return this._isEnable}next(s){if(!this._isDestroyed&&this._isEnable&&(this.filterCase.isEmpty||this.filterCase.processChain(s).isOK)){this.isNextProcess=!0,this.value=s;for(let e=0;e<this.listeners.length;e++)this.listeners[e].send(s);this.isNextProcess=!1,this.listenersForUnsubscribe.length&&this.handleListenersForUnsubscribe()}}stream(s){if(!this._isDestroyed&&this._isEnable)for(let e=0;e<s.length;e++)this.next(s[e])}handleListenersForUnsubscribe(){const s=this.listenersForUnsubscribe.length;for(let e=0;e<s;e++)this.unSubscribe(this.listenersForUnsubscribe[e]);this.listenersForUnsubscribe.length=0}unSubscribe(s){this._isDestroyed||(this.isNextProcess&&s?this.listenersForUnsubscribe.push(s):this.listeners&&i(this.listeners,s))}destroy(){this.value=null,this.unsubscribeAll(),this.listeners=null,this._isDestroyed=!0}unsubscribeAll(){this._isDestroyed||(this.listeners.length=0)}getValue(){if(!this._isDestroyed)return this.value}size(){return this._isDestroyed?0:this.listeners.length}subscribe(s,e){if(!this.isSubsValid(s))return;const i=new h(this,!1);return this.addObserver(i,s,e),i}addObserver(s,e,i){s.subscribe(e,i),this.listeners.push(s)}isSubsValid(s){return!this._isDestroyed&&!!s}pipe(){if(this._isDestroyed)return;const s=new h(this,!0);return this.listeners.push(s),s}get isDestroyed(){return this._isDestroyed}}class u extends h{constructor(s,e){super(s,e)}get order(){return this._order}set order(s){!this.observable||this.observable&&this.observable.isDestroyed?this._order=void 0:(this._order=s,this.observable.sortByOrder())}subscribe(s,e){return super.subscribe(s,e),this}setOnce(){return super.setOnce()}unsubscribeByNegative(s){return super.unsubscribeByNegative(s)}unsubscribeByPositive(s){return super.unsubscribeByPositive(s)}emitByNegative(s){return super.emitByNegative(s)}emitByPositive(s){return super.emitByPositive(s)}emitMatch(s){return super.emitMatch(s)}}const c=window;c.Observable=o,c.Collector=class{constructor(){this.list=[],this._isDestroyed=!1}collect(...s){this._isDestroyed||this.list.push(...s)}unsubscribe(s){this._isDestroyed||(s?.unsubscribe(),i(this.list,s))}unsubscribeAll(){if(!this._isDestroyed)for(;this.list.length>0;)this.unsubscribe(this.list.pop())}size(){return this._isDestroyed?0:this.list.length}destroy(){this.unsubscribeAll(),this.list.length=0,this.list=0,this._isDestroyed=!0}get isDestroyed(){return this._isDestroyed}},c.OrderedObservable=class extends o{constructor(){super(...arguments),this.sortDirection=s}setAscendingSort(){return this.sortDirection=s,this.sortByOrder()}setDescendingSort(){return this.sortDirection=e,this.sortByOrder()}sortByOrder(){return!this._isDestroyed&&(this.listeners.sort(this.sortDirection),!0)}subscribe(s,e){if(!this.isSubsValid(s))return;const i=new u(this,!1);return this.addObserver(i,s,e),i}pipe(){if(this._isDestroyed)return;const s=new u(this,!0);return this.listeners.push(s),s}unSubscribe(s){this._isDestroyed||(this.isNextProcess&&s?this.listenersForUnsubscribe.push(s):this.listeners&&function(s,e){const i=s.indexOf(e);-1!==i&&s.splice(i,1)}(this.listeners,s))}}})();
|
package/src/outLib/Pipe.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare abstract class Pipe<T> implements ISubscribe<T> {
|
|
|
6
6
|
setOnce(): ISubscribe<T>;
|
|
7
7
|
unsubscribeByNegative(condition: ICallback<T>): ISetup<T>;
|
|
8
8
|
unsubscribeByPositive(condition: ICallback<T>): ISetup<T>;
|
|
9
|
+
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
9
10
|
emitByNegative(condition: ICallback<T>): ISetup<T>;
|
|
10
11
|
emitByPositive(condition: ICallback<T>): ISetup<T>;
|
|
11
12
|
refine(condition: ICallback<T>): ISetup<T>;
|
package/src/outLib/Pipe.js
CHANGED
package/src/outLib/Types.d.ts
CHANGED
|
@@ -64,22 +64,24 @@ export type ISend<T> = {
|
|
|
64
64
|
send(value: T): void;
|
|
65
65
|
};
|
|
66
66
|
export type IUnsubscribeByNegative<T> = {
|
|
67
|
-
unsubscribeByNegative(condition: ICallback<
|
|
67
|
+
unsubscribeByNegative(condition: ICallback<T>): ISetup<T>;
|
|
68
68
|
};
|
|
69
69
|
export type IOrderedUnsubscribeByNegative<T> = {
|
|
70
|
-
unsubscribeByNegative(condition: ICallback<
|
|
70
|
+
unsubscribeByNegative(condition: ICallback<T>): IOrderedSetup<T>;
|
|
71
71
|
};
|
|
72
72
|
export type IUnsubscribeByPositive<T> = {
|
|
73
|
-
unsubscribeByPositive(condition: ICallback<
|
|
73
|
+
unsubscribeByPositive(condition: ICallback<T>): ISetup<T>;
|
|
74
|
+
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
74
75
|
};
|
|
75
76
|
export type IOrderedUnsubscribeByPositive<T> = {
|
|
76
|
-
unsubscribeByPositive(condition: ICallback<
|
|
77
|
+
unsubscribeByPositive(condition: ICallback<T>): IOrderedSetup<T>;
|
|
78
|
+
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
77
79
|
};
|
|
78
80
|
export type IEmitByNegative<T> = {
|
|
79
|
-
emitByNegative(condition: ICallback<
|
|
81
|
+
emitByNegative(condition: ICallback<T>): ISetup<T>;
|
|
80
82
|
};
|
|
81
83
|
export type IOrderedEmitByNegative<T> = {
|
|
82
|
-
emitByNegative(condition: ICallback<
|
|
84
|
+
emitByNegative(condition: ICallback<T>): IOrderedSetup<T>;
|
|
83
85
|
};
|
|
84
86
|
export type IEmitByPositive<T> = {
|
|
85
87
|
emitByPositive(condition: ICallback<T>): ISetup<T>;
|