evg_observable 1.0.7 → 1.0.11
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 +145 -1
- package/package.json +13 -3
- package/src/outLib/Observables/Observable.d.ts +3 -0
- package/src/outLib/Observables/Observable.js +16 -0
- package/src/outLib/Observables/Observable.js.map +1 -1
- package/src/Libraries/FunctionLibs.ts +0 -9
- package/src/Libraries/Observables/Collector.ts +0 -44
- package/src/Libraries/Observables/Observable.ts +0 -206
- package/src/Libraries/Observables/OrderedObservable.ts +0 -86
- package/src/Libraries/Observables/Types.ts +0 -159
- package/src/Libraries/TickGenerator.ts +0 -178
- package/src/Libraries/Types.ts +0 -27
- package/test/Collector.unit.test.ts +0 -244
- package/test/FunctionLib.unit.test.ts +0 -86
- package/test/OrderedObservable.unit.test.ts +0 -826
- package/test/observable.unit.test.ts +0 -681
- package/test/tsconfig.json +0 -21
|
@@ -1,681 +0,0 @@
|
|
|
1
|
-
import {suite, test} from '@testdeck/mocha';
|
|
2
|
-
import * as _chai from 'chai';
|
|
3
|
-
import {expect} from 'chai';
|
|
4
|
-
import {Observable} from "../src/Libraries/Observables/Observable";
|
|
5
|
-
import {IOrder, IPause} from "../src/Libraries/Observables/Types";
|
|
6
|
-
|
|
7
|
-
_chai.should();
|
|
8
|
-
_chai.expect;
|
|
9
|
-
|
|
10
|
-
@suite
|
|
11
|
-
class ObservableUnitTest {
|
|
12
|
-
private OBSERVABLE$: Observable<string>;
|
|
13
|
-
|
|
14
|
-
before() {
|
|
15
|
-
this.OBSERVABLE$ = new Observable('');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@test 'Observable is created'() {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
expect(this.OBSERVABLE$.value).to.be.equal('');
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
expect(this.OBSERVABLE$.listeners).to.be.eql([]);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@test 'Add one subscriber'() {
|
|
26
|
-
const subscribeObject = this.OBSERVABLE$.subscribe((value: string) => console.log(value));
|
|
27
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
const once = subscribeObject.once;
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
expect(once.isOnce).to.be.equal(false);
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
expect(once.isFinished).to.be.equal(false);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@test 'unsubscribe one by subject'() {
|
|
37
|
-
const subscribeObject = this.OBSERVABLE$.subscribe((value: string) => console.log(value));
|
|
38
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
39
|
-
subscribeObject.unsubscribe();
|
|
40
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@test 'unsubscribe one by observable'() {
|
|
44
|
-
const subscribeObject = this.OBSERVABLE$.subscribe((value: string) => console.log(value));
|
|
45
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
46
|
-
this.OBSERVABLE$.unSubscribe(subscribeObject);
|
|
47
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@test 'unsubscribe all by ony'() {
|
|
51
|
-
this.OBSERVABLE$.subscribe((value: string) => console.log(value));
|
|
52
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
53
|
-
this.OBSERVABLE$.unsubscribeAll();
|
|
54
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@test 'Add one subscriber and listen one event'() {
|
|
58
|
-
const str = '1';
|
|
59
|
-
const listener = (value: string) => {
|
|
60
|
-
expect(value).to.be.equal(str);
|
|
61
|
-
};
|
|
62
|
-
this.OBSERVABLE$.subscribe(listener);
|
|
63
|
-
this.OBSERVABLE$.next(str);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@test 'Add one subscriber and listen ten events'() {
|
|
67
|
-
const str = '0123456789';
|
|
68
|
-
let counter = 0;
|
|
69
|
-
const listener = (value: string) => expect(value).to.be.equal(str[counter]);
|
|
70
|
-
|
|
71
|
-
this.OBSERVABLE$.subscribe(listener);
|
|
72
|
-
for (; counter < 10; counter++) this.OBSERVABLE$.next(str[counter]);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@test 'Add one subscriber and get value after one change'() {
|
|
76
|
-
const str = '0123456789';
|
|
77
|
-
let counter = 0;
|
|
78
|
-
const listener = (value: string) => value;
|
|
79
|
-
|
|
80
|
-
this.OBSERVABLE$.subscribe(listener);
|
|
81
|
-
for (; counter < 1; counter++) this.OBSERVABLE$.next(str[counter]);
|
|
82
|
-
|
|
83
|
-
expect(this.OBSERVABLE$.getValue()).to.be.equal('0');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@test 'Add one subscriber and get value after five changes'() {
|
|
87
|
-
const str = '0123456789';
|
|
88
|
-
let counter = 0;
|
|
89
|
-
const listener = (value: string) => value;
|
|
90
|
-
|
|
91
|
-
this.OBSERVABLE$.subscribe(listener);
|
|
92
|
-
for (; counter < 5; counter++) this.OBSERVABLE$.next(str[counter]);
|
|
93
|
-
|
|
94
|
-
expect(this.OBSERVABLE$.getValue()).to.be.equal('4');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@test 'Add one subscriber and get value after ten changes'() {
|
|
98
|
-
const str = '0123456789';
|
|
99
|
-
let counter = 0;
|
|
100
|
-
const listener = (value: string) => value;
|
|
101
|
-
|
|
102
|
-
this.OBSERVABLE$.subscribe(listener);
|
|
103
|
-
for (; counter < 10; counter++) this.OBSERVABLE$.next(str[counter]);
|
|
104
|
-
|
|
105
|
-
expect(this.OBSERVABLE$.getValue()).to.be.equal('9');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@test 'Add one by pipe and "once"'() {
|
|
109
|
-
const str = '0123456789';
|
|
110
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
111
|
-
const subscribeObject = this.OBSERVABLE$
|
|
112
|
-
.pipe()
|
|
113
|
-
.setOnce()
|
|
114
|
-
.subscribe(listener);
|
|
115
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
116
|
-
this.OBSERVABLE$.next(str);
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
expect(subscribeObject.once.isOnce).to.be.equal(true);
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
expect(subscribeObject.once.isFinished).to.be.equal(true);
|
|
121
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@test 'Add one by pipe and "once" after 10 changes'() {
|
|
125
|
-
const str = '0123456789';
|
|
126
|
-
let counter = 0;
|
|
127
|
-
const listener = (value: string) => expect(value).to.be.equal(str[0]);
|
|
128
|
-
|
|
129
|
-
const subscribeObject = this.OBSERVABLE$
|
|
130
|
-
.pipe()
|
|
131
|
-
.setOnce()
|
|
132
|
-
.subscribe(listener);
|
|
133
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
134
|
-
// @ts-ignore
|
|
135
|
-
expect(subscribeObject.once.isOnce).to.be.equal(true);
|
|
136
|
-
for (; counter < 10; counter++) this.OBSERVABLE$.next(str[counter]);
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
expect(subscribeObject.once.isFinished).to.be.equal(true);
|
|
139
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
@test 'Add bad pipe'() {
|
|
143
|
-
const str = '0123456789';
|
|
144
|
-
this.OBSERVABLE$.pipe();
|
|
145
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
146
|
-
this.OBSERVABLE$.next(str);
|
|
147
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
@test 'Add one by pipe and "unsubscribeByNegative true"'() {
|
|
151
|
-
const str = '0123456789';
|
|
152
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
153
|
-
const condition = () => true;
|
|
154
|
-
const subscribeObject = this.OBSERVABLE$
|
|
155
|
-
.pipe()
|
|
156
|
-
.unsubscribeByNegative(condition)
|
|
157
|
-
.subscribe(listener);
|
|
158
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
159
|
-
this.OBSERVABLE$.next(str);
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
expect(subscribeObject.unsubscribeByNegativeCondition).to.be.equal(condition);
|
|
162
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
@test 'Add one by pipe and "unsubscribeByNegative false"'() {
|
|
166
|
-
const str = '0123456789';
|
|
167
|
-
const listener = (value: string) => expect(value).to.be.equal(null);
|
|
168
|
-
const condition = () => false;
|
|
169
|
-
const subscribeObject = this.OBSERVABLE$
|
|
170
|
-
.pipe()
|
|
171
|
-
.unsubscribeByNegative(condition)
|
|
172
|
-
.subscribe(listener);
|
|
173
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
174
|
-
this.OBSERVABLE$.next(str);
|
|
175
|
-
// @ts-ignore
|
|
176
|
-
expect(subscribeObject.unsubscribeByNegativeCondition).to.be.equal(null);
|
|
177
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
@test 'Add one by pipe and "unsubscribeByNegative" (5 positive, 5 negative)'() {
|
|
181
|
-
let counter = 0;
|
|
182
|
-
const str = '0123456789';
|
|
183
|
-
const listener = (value: string) => expect(value).to.be.equal(str[counter]);
|
|
184
|
-
const condition = () => counter < 5;
|
|
185
|
-
const subscribeObject = this.OBSERVABLE$
|
|
186
|
-
.pipe()
|
|
187
|
-
.unsubscribeByNegative(condition)
|
|
188
|
-
.subscribe(listener);
|
|
189
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
190
|
-
for (; counter < 10; counter++) {
|
|
191
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
192
|
-
}
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
expect(subscribeObject.unsubscribeByNegativeCondition).to.be.equal(null);
|
|
195
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@test 'Add one by pipe and "unsubscribeByPositive true"'() {
|
|
199
|
-
const str = '0123456789';
|
|
200
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
201
|
-
const condition = () => true;
|
|
202
|
-
const subscribeObject = this.OBSERVABLE$
|
|
203
|
-
.pipe()
|
|
204
|
-
.unsubscribeByPositive(condition)
|
|
205
|
-
.subscribe(listener);
|
|
206
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
207
|
-
this.OBSERVABLE$.next(str);
|
|
208
|
-
// @ts-ignore
|
|
209
|
-
expect(subscribeObject.unsubscribeByPositiveCondition).to.be.equal(null);
|
|
210
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
@test 'Add one by pipe and "unsubscribeByPositive false"'() {
|
|
214
|
-
const str = '0123456789';
|
|
215
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
216
|
-
const condition = () => false;
|
|
217
|
-
const subscribeObject = this.OBSERVABLE$
|
|
218
|
-
.pipe()
|
|
219
|
-
.unsubscribeByPositive(condition)
|
|
220
|
-
.subscribe(listener);
|
|
221
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
222
|
-
this.OBSERVABLE$.next(str);
|
|
223
|
-
// @ts-ignore
|
|
224
|
-
expect(subscribeObject.unsubscribeByPositiveCondition).to.be.equal(condition);
|
|
225
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
@test 'Add one by pipe and "unsubscribeByPositive" (5 negative, 5 positive)'() {
|
|
229
|
-
let counter = 0;
|
|
230
|
-
const str = '0123456789';
|
|
231
|
-
const listener = (value: string) => expect(value).to.be.equal(str[counter]);
|
|
232
|
-
const condition = () => counter > 4;
|
|
233
|
-
const subscribeObject = this.OBSERVABLE$
|
|
234
|
-
.pipe()
|
|
235
|
-
.unsubscribeByPositive(condition)
|
|
236
|
-
.subscribe(listener);
|
|
237
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
238
|
-
for (; counter < 10; counter++) {
|
|
239
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
240
|
-
}
|
|
241
|
-
// @ts-ignore
|
|
242
|
-
expect(subscribeObject.unsubscribeByNegativeCondition).to.be.equal(null);
|
|
243
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
@test 'Add one by pipe and "emitByNegative true"'() {
|
|
247
|
-
const str = '0123456789';
|
|
248
|
-
const listener = (value: string) => expect(value).to.be.equal(null);
|
|
249
|
-
const condition = () => true;
|
|
250
|
-
const subscribeObject = this.OBSERVABLE$
|
|
251
|
-
.pipe()
|
|
252
|
-
.emitByNegative(condition)
|
|
253
|
-
.subscribe(listener);
|
|
254
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
255
|
-
this.OBSERVABLE$.next(str);
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
expect(subscribeObject.emitByNegativeCondition).to.be.equal(condition);
|
|
258
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
@test 'Add one by pipe and "emitByNegative false"'() {
|
|
262
|
-
const str = '0123456789';
|
|
263
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
264
|
-
const condition = () => false;
|
|
265
|
-
const subscribeObject = this.OBSERVABLE$
|
|
266
|
-
.pipe()
|
|
267
|
-
.emitByNegative(condition)
|
|
268
|
-
.subscribe(listener);
|
|
269
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
270
|
-
this.OBSERVABLE$.next(str);
|
|
271
|
-
// @ts-ignore
|
|
272
|
-
expect(subscribeObject.emitByNegativeCondition).to.be.equal(condition);
|
|
273
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
@test 'Add one by pipe and "emitByNegative" (5 negative, 5 positive)'() {
|
|
277
|
-
let counter = 0;
|
|
278
|
-
const str = '0123456789';
|
|
279
|
-
const listener = (value: string) => {
|
|
280
|
-
expect(value).to.be.equal(str[counter]);
|
|
281
|
-
expect(true).to.be.equal(counter > -1 && counter < 5);
|
|
282
|
-
};
|
|
283
|
-
const condition = () => counter > 4;
|
|
284
|
-
const subscribeObject = this.OBSERVABLE$
|
|
285
|
-
.pipe()
|
|
286
|
-
.emitByNegative(condition)
|
|
287
|
-
.subscribe(listener);
|
|
288
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
289
|
-
for (; counter < 10; counter++) {
|
|
290
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
291
|
-
}
|
|
292
|
-
// @ts-ignore
|
|
293
|
-
expect(subscribeObject.emitByNegativeCondition).to.be.equal(condition);
|
|
294
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
@test 'Add one by pipe and "emitByNegative" (5 positive 5 negative)'() {
|
|
298
|
-
let counter = 0;
|
|
299
|
-
const str = '0123456789';
|
|
300
|
-
const listener = (value: string) => {
|
|
301
|
-
expect(value).to.be.equal(str[counter]);
|
|
302
|
-
expect(true).to.be.equal(counter > 4 && counter < 10);
|
|
303
|
-
};
|
|
304
|
-
const condition = () => counter < 5;
|
|
305
|
-
const subscribeObject = this.OBSERVABLE$
|
|
306
|
-
.pipe()
|
|
307
|
-
.emitByNegative(condition)
|
|
308
|
-
.subscribe(listener);
|
|
309
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
310
|
-
for (; counter < 10; counter++) {
|
|
311
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
312
|
-
}
|
|
313
|
-
// @ts-ignore
|
|
314
|
-
expect(subscribeObject.emitByNegativeCondition).to.be.equal(condition);
|
|
315
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
@test 'Add one by pipe and "emitByPositive true"'() {
|
|
319
|
-
const str = '0123456789';
|
|
320
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
321
|
-
const condition = () => true;
|
|
322
|
-
const subscribeObject = this.OBSERVABLE$
|
|
323
|
-
.pipe()
|
|
324
|
-
.emitByPositive(condition)
|
|
325
|
-
.subscribe(listener);
|
|
326
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
327
|
-
this.OBSERVABLE$.next(str);
|
|
328
|
-
// @ts-ignore
|
|
329
|
-
expect(subscribeObject.emitByPositiveCondition).to.be.equal(condition);
|
|
330
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
@test 'Add one by pipe and "emitByPositive false"'() {
|
|
334
|
-
const str = '0123456789';
|
|
335
|
-
const listener = (value: string) => expect(value).to.be.equal(null);
|
|
336
|
-
const condition = () => false;
|
|
337
|
-
const subscribeObject = this.OBSERVABLE$
|
|
338
|
-
.pipe()
|
|
339
|
-
.emitByPositive(condition)
|
|
340
|
-
.subscribe(listener);
|
|
341
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
342
|
-
this.OBSERVABLE$.next(str);
|
|
343
|
-
// @ts-ignore
|
|
344
|
-
expect(subscribeObject.emitByPositiveCondition).to.be.equal(condition);
|
|
345
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
@test 'Add one by pipe and "emitByPositive" (5 negative, 5 positive)'() {
|
|
349
|
-
let counter = 0;
|
|
350
|
-
const str = '0123456789';
|
|
351
|
-
const listener = (value: string) => {
|
|
352
|
-
expect(value).to.be.equal(str[counter]);
|
|
353
|
-
expect(true).to.be.equal(counter > 4 && counter < 10);
|
|
354
|
-
};
|
|
355
|
-
const condition = () => counter > 4;
|
|
356
|
-
const subscribeObject = this.OBSERVABLE$
|
|
357
|
-
.pipe()
|
|
358
|
-
.emitByPositive(condition)
|
|
359
|
-
.subscribe(listener);
|
|
360
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
361
|
-
for (; counter < 10; counter++) {
|
|
362
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
363
|
-
}
|
|
364
|
-
// @ts-ignore
|
|
365
|
-
expect(subscribeObject.emitByPositiveCondition).to.be.equal(condition);
|
|
366
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
@test 'Add one by pipe and "emitByPositive" (5 positive 5 negative)'() {
|
|
370
|
-
let counter = 0;
|
|
371
|
-
const str = '0123456789';
|
|
372
|
-
const listener = (value: string) => {
|
|
373
|
-
expect(value).to.be.equal(str[counter]);
|
|
374
|
-
expect(true).to.be.equal(counter > -1 && counter < 5);
|
|
375
|
-
};
|
|
376
|
-
const condition = () => counter < 5;
|
|
377
|
-
const subscribeObject = this.OBSERVABLE$
|
|
378
|
-
.pipe()
|
|
379
|
-
.emitByPositive(condition)
|
|
380
|
-
.subscribe(listener);
|
|
381
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
382
|
-
for (; counter < 10; counter++) {
|
|
383
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
384
|
-
}
|
|
385
|
-
// @ts-ignore
|
|
386
|
-
expect(subscribeObject.emitByPositiveCondition).to.be.equal(condition);
|
|
387
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
@test 'Add one by pipe and "emitMatch true"'() {
|
|
391
|
-
const str = '0123456789';
|
|
392
|
-
const condition = () => '0123456789';
|
|
393
|
-
const listener = (value: string) => expect(value).to.be.equal(str);
|
|
394
|
-
const subscribeObject = this.OBSERVABLE$
|
|
395
|
-
.pipe()
|
|
396
|
-
.emitMatch(condition)
|
|
397
|
-
.subscribe(listener);
|
|
398
|
-
// @ts-ignore
|
|
399
|
-
expect(subscribeObject.emitMatchCondition).to.be.equal(condition);
|
|
400
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
@test 'Add one by pipe and "emitMatch false"'() {
|
|
404
|
-
const str = '0123456789';
|
|
405
|
-
const condition = () => '0123456789';
|
|
406
|
-
const listener = (value: string) => expect(value).to.be.equal(null);
|
|
407
|
-
const subscribeObject = this.OBSERVABLE$
|
|
408
|
-
.pipe()
|
|
409
|
-
.emitMatch(condition)
|
|
410
|
-
.subscribe(listener);
|
|
411
|
-
// @ts-ignore
|
|
412
|
-
expect(subscribeObject.emitMatchCondition).to.be.equal(condition);
|
|
413
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
@test 'Add one by pipe and "emitMatch 10 elements" (on value "0")'() {
|
|
417
|
-
let counter = 0;
|
|
418
|
-
const str = '0123456789';
|
|
419
|
-
const listener = (value: string) => {
|
|
420
|
-
expect(value).to.be.equal('0');
|
|
421
|
-
expect(true).to.be.equal(counter === 0);
|
|
422
|
-
};
|
|
423
|
-
const condition = () => '0';
|
|
424
|
-
const subscribeObject = this.OBSERVABLE$
|
|
425
|
-
.pipe()
|
|
426
|
-
.emitMatch(condition)
|
|
427
|
-
.subscribe(listener);
|
|
428
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
429
|
-
for (; counter < 10; counter++) {
|
|
430
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
431
|
-
}
|
|
432
|
-
// @ts-ignore
|
|
433
|
-
expect(subscribeObject.emitMatchCondition).to.be.equal(condition);
|
|
434
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
@test 'Add one by pipe and "emitMatch 10 elements" (on value "9")'() {
|
|
438
|
-
let counter = 0;
|
|
439
|
-
const str = '0123456789';
|
|
440
|
-
const listener = (value: string) => {
|
|
441
|
-
expect(value).to.be.equal('9');
|
|
442
|
-
expect(true).to.be.equal(counter === 9);
|
|
443
|
-
};
|
|
444
|
-
const condition = () => '9';
|
|
445
|
-
const subscribeObject = this.OBSERVABLE$
|
|
446
|
-
.pipe()
|
|
447
|
-
.emitMatch(condition)
|
|
448
|
-
.subscribe(listener);
|
|
449
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
450
|
-
for (; counter < 10; counter++) {
|
|
451
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
452
|
-
}
|
|
453
|
-
// @ts-ignore
|
|
454
|
-
expect(subscribeObject.emitMatchCondition).to.be.equal(condition);
|
|
455
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
@test 'Add one by pipe and "emitMatch 10 elements" (on value "5")'() {
|
|
459
|
-
let counter = 0;
|
|
460
|
-
const str = '0123456789';
|
|
461
|
-
const listener = (value: string) => {
|
|
462
|
-
expect(value).to.be.equal('5');
|
|
463
|
-
expect(true).to.be.equal(counter === 5);
|
|
464
|
-
};
|
|
465
|
-
const condition = () => '5';
|
|
466
|
-
const subscribeObject = this.OBSERVABLE$
|
|
467
|
-
.pipe()
|
|
468
|
-
.emitMatch(condition)
|
|
469
|
-
.subscribe(listener);
|
|
470
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
471
|
-
for (; counter < 10; counter++) {
|
|
472
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
473
|
-
}
|
|
474
|
-
// @ts-ignore
|
|
475
|
-
expect(subscribeObject.emitMatchCondition).to.be.equal(condition);
|
|
476
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
@test 'pause / resume'() {
|
|
480
|
-
let counter = 0;
|
|
481
|
-
let accumulatorStr = '';
|
|
482
|
-
const str = '0123456789';
|
|
483
|
-
const listener = (value: string) => accumulatorStr += value;
|
|
484
|
-
const subscribeObject = this.OBSERVABLE$.subscribe(listener);
|
|
485
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
486
|
-
for (; counter < 10; counter++) {
|
|
487
|
-
(counter === 4) && (<IPause><any>subscribeObject).pause();
|
|
488
|
-
(counter === 8) && (<IPause><any>subscribeObject).resume();
|
|
489
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
490
|
-
}
|
|
491
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
492
|
-
expect(accumulatorStr).to.be.equal('012389');
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
@test 'order identification'() {
|
|
496
|
-
const listener = (value: string) => value;
|
|
497
|
-
const subscribeObject = <IOrder><any>this.OBSERVABLE$.subscribe(listener);
|
|
498
|
-
subscribeObject.order = 11011;
|
|
499
|
-
expect(subscribeObject.order).to.be.equal(11011);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
@test 'observable disable/enable'() {
|
|
503
|
-
let counter = 0;
|
|
504
|
-
let accumulatorStr = '';
|
|
505
|
-
const str = '0123456789';
|
|
506
|
-
const listener = (value: string) => accumulatorStr += value;
|
|
507
|
-
const subscribeObject = this.OBSERVABLE$.subscribe(listener);
|
|
508
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
509
|
-
for (; counter < 10; counter++) {
|
|
510
|
-
(counter === 4) && this.OBSERVABLE$.disable();
|
|
511
|
-
(counter === 8) && this.OBSERVABLE$.enable();
|
|
512
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
513
|
-
}
|
|
514
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
515
|
-
expect(this.OBSERVABLE$.isEnable).to.be.equal(true);
|
|
516
|
-
expect(accumulatorStr).to.be.equal('012389');
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
@test 'observable destroy'() {
|
|
520
|
-
let counter = 0;
|
|
521
|
-
let accumulatorStr = '';
|
|
522
|
-
const str = '0123456789';
|
|
523
|
-
const listener = (value: string) => accumulatorStr += value;
|
|
524
|
-
const subscribeObject = this.OBSERVABLE$.subscribe(listener);
|
|
525
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
526
|
-
for (; counter < 10; counter++) {
|
|
527
|
-
(counter === 4) && this.OBSERVABLE$.disable();
|
|
528
|
-
(counter === 8) && this.OBSERVABLE$.enable();
|
|
529
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
530
|
-
}
|
|
531
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
532
|
-
expect(this.OBSERVABLE$.isEnable).to.be.equal(true);
|
|
533
|
-
expect(accumulatorStr).to.be.equal('012389');
|
|
534
|
-
this.OBSERVABLE$.destroy();
|
|
535
|
-
expect(this.OBSERVABLE$.isDestroyed).to.be.equal(true);
|
|
536
|
-
// @ts-ignore
|
|
537
|
-
expect(this.OBSERVABLE$.value).to.be.equal(0);
|
|
538
|
-
// @ts-ignore
|
|
539
|
-
expect(this.OBSERVABLE$.listeners).to.be.equal(0);
|
|
540
|
-
// @ts-ignore
|
|
541
|
-
expect(subscribeObject.observable).to.be.equal(0);
|
|
542
|
-
// @ts-ignore
|
|
543
|
-
expect(subscribeObject.listener).to.be.equal(0);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
@test 'defect field "observable" from subscribeObject'() {
|
|
547
|
-
const listener = (value: string) => {
|
|
548
|
-
expect(value).to.be.equal('ERROR WAY');
|
|
549
|
-
};
|
|
550
|
-
const subscribeObject = this.OBSERVABLE$.subscribe(listener);
|
|
551
|
-
// @ts-ignore
|
|
552
|
-
subscribeObject.observable = 0;
|
|
553
|
-
this.OBSERVABLE$.next('some data');
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
@test 'defect field "listener" from subscribeObject'() {
|
|
557
|
-
const listener = (value: string) => {
|
|
558
|
-
expect(value).to.be.equal('ERROR DATA');
|
|
559
|
-
};
|
|
560
|
-
const subscribeObject = this.OBSERVABLE$.subscribe(listener);
|
|
561
|
-
// @ts-ignore
|
|
562
|
-
subscribeObject.listener = 0;
|
|
563
|
-
this.OBSERVABLE$.next('VALID DATA');
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
@test 'multi use'() {
|
|
567
|
-
let counter = 0;
|
|
568
|
-
const str = '0123456789';
|
|
569
|
-
const subscribeObject1 = this.OBSERVABLE$.subscribe((value) => {
|
|
570
|
-
expect(value).to.be.equal(str[counter]);
|
|
571
|
-
(<IOrder><any>subscribeObject1).order = 1;
|
|
572
|
-
});
|
|
573
|
-
const subscribeObject2 = this.OBSERVABLE$.subscribe((value) => {
|
|
574
|
-
expect(value).to.be.equal(str[counter]);
|
|
575
|
-
(<IOrder><any>subscribeObject2).order = 2;
|
|
576
|
-
});
|
|
577
|
-
const subscribeObject3 = this.OBSERVABLE$.subscribe((value) => {
|
|
578
|
-
expect(value).to.be.equal(str[counter]);
|
|
579
|
-
(<IOrder><any>subscribeObject3).order = 3;
|
|
580
|
-
});
|
|
581
|
-
const subscribeObject4 = this.OBSERVABLE$.subscribe((value) => {
|
|
582
|
-
expect(value).to.be.equal(str[counter]);
|
|
583
|
-
(<IOrder><any>subscribeObject4).order = 4;
|
|
584
|
-
});
|
|
585
|
-
const subscribeObject5 = this.OBSERVABLE$.subscribe((value) => {
|
|
586
|
-
expect(value).to.be.equal(str[counter]);
|
|
587
|
-
(<IOrder><any>subscribeObject5).order = 5;
|
|
588
|
-
});
|
|
589
|
-
for (; counter < str.length; counter++) {
|
|
590
|
-
this.OBSERVABLE$.next(str[counter]);
|
|
591
|
-
}
|
|
592
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(5);
|
|
593
|
-
expect((<IOrder><any>subscribeObject1).order).to.be.equal(1);
|
|
594
|
-
expect((<IOrder><any>subscribeObject2).order).to.be.equal(2);
|
|
595
|
-
expect((<IOrder><any>subscribeObject3).order).to.be.equal(3);
|
|
596
|
-
expect((<IOrder><any>subscribeObject4).order).to.be.equal(4);
|
|
597
|
-
expect((<IOrder><any>subscribeObject5).order).to.be.equal(5);
|
|
598
|
-
subscribeObject1.unsubscribe();
|
|
599
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(4);
|
|
600
|
-
subscribeObject2.unsubscribe();
|
|
601
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(3);
|
|
602
|
-
subscribeObject3.unsubscribe();
|
|
603
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(2);
|
|
604
|
-
subscribeObject4.unsubscribe();
|
|
605
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
606
|
-
subscribeObject5.unsubscribe();
|
|
607
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
@test 'destroy and try to use next'() {
|
|
611
|
-
const subscribeObject1 = this.OBSERVABLE$.subscribe((value) => {
|
|
612
|
-
expect(value).to.be.equal('ERROR DATA');
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
this.OBSERVABLE$.destroy();
|
|
616
|
-
this.OBSERVABLE$.next('VALID DATA');
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
@test 'destroy and try to use unSubscribe'() {
|
|
620
|
-
const subscribeObject1 = this.OBSERVABLE$.subscribe((value) => {
|
|
621
|
-
expect(value).to.be.equal('ERROR DATA');
|
|
622
|
-
});
|
|
623
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
624
|
-
this.OBSERVABLE$.destroy();
|
|
625
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
626
|
-
this.OBSERVABLE$.unSubscribe(subscribeObject1);
|
|
627
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
628
|
-
expect(this.OBSERVABLE$.isDestroyed).to.be.equal(true);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
@test 'destroy and try to use unSubscribeAll'() {
|
|
632
|
-
const subscribeObject1 = this.OBSERVABLE$.subscribe((value) => {
|
|
633
|
-
expect(value).to.be.equal('ERROR DATA');
|
|
634
|
-
});
|
|
635
|
-
const subscribeObject2 = this.OBSERVABLE$.subscribe((value) => {
|
|
636
|
-
expect(value).to.be.equal('ERROR DATA');
|
|
637
|
-
});
|
|
638
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(2);
|
|
639
|
-
this.OBSERVABLE$.destroy();
|
|
640
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
641
|
-
this.OBSERVABLE$.unsubscribeAll();
|
|
642
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
643
|
-
expect(this.OBSERVABLE$.isDestroyed).to.be.equal(true);
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
@test 'destroy and try to use getValue'() {
|
|
647
|
-
this.OBSERVABLE$.subscribe((value) => {
|
|
648
|
-
expect(value).to.be.equal('SOME DATA');
|
|
649
|
-
});
|
|
650
|
-
this.OBSERVABLE$.next('SOME DATA');
|
|
651
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
652
|
-
this.OBSERVABLE$.destroy();
|
|
653
|
-
expect(this.OBSERVABLE$.getValue()).to.be.equal(undefined);
|
|
654
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
655
|
-
expect(this.OBSERVABLE$.isDestroyed).to.be.equal(true);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
@test 'destroy and try to use subscribe'() {
|
|
659
|
-
this.OBSERVABLE$.subscribe((value) => {
|
|
660
|
-
expect(value).to.be.equal('SOME DATA');
|
|
661
|
-
});
|
|
662
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
663
|
-
this.OBSERVABLE$.destroy();
|
|
664
|
-
this.OBSERVABLE$.subscribe((value) => {
|
|
665
|
-
expect(value).to.be.equal('SOME DATA');
|
|
666
|
-
});
|
|
667
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
668
|
-
expect(this.OBSERVABLE$.isDestroyed).to.be.equal(true);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
@test 'destroy and try to use pipe'() {
|
|
672
|
-
this.OBSERVABLE$.subscribe((value) => {
|
|
673
|
-
expect(value).to.be.equal('SOME DATA');
|
|
674
|
-
});
|
|
675
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(1);
|
|
676
|
-
this.OBSERVABLE$.destroy();
|
|
677
|
-
expect(this.OBSERVABLE$.pipe()).to.be.equal(undefined);
|
|
678
|
-
expect(this.OBSERVABLE$.size()).to.be.equal(0);
|
|
679
|
-
expect(this.OBSERVABLE$.isDestroyed).to.be.equal(true);
|
|
680
|
-
}
|
|
681
|
-
}
|
package/test/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": "./",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"experimentalDecorators": true,
|
|
7
|
-
"strictPropertyInitialization": false,
|
|
8
|
-
"isolatedModules": false,
|
|
9
|
-
"strict": false,
|
|
10
|
-
"noImplicitAny": false,
|
|
11
|
-
"typeRoots" : [
|
|
12
|
-
"../node_modules/@types"
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
"exclude": [
|
|
16
|
-
"../node_modules"
|
|
17
|
-
],
|
|
18
|
-
"include": [
|
|
19
|
-
"./**/*.ts"
|
|
20
|
-
]
|
|
21
|
-
}
|