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,159 +0,0 @@
|
|
|
1
|
-
export type ICallback<T> = (value?: T) => any;
|
|
2
|
-
|
|
3
|
-
export type ISubscribe<T> = {
|
|
4
|
-
subscribe(listener: IListener<T>): ISubscriptionLike<T>;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type IListener<T> = ICallback<T>;
|
|
8
|
-
|
|
9
|
-
export type IDestroy = {
|
|
10
|
-
destroy(): void;
|
|
11
|
-
isDestroyed: boolean;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type IOnceMarker = {
|
|
15
|
-
isOnce: boolean;
|
|
16
|
-
isFinished: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type IOrder = {
|
|
20
|
-
order: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type IOnce<T> = {
|
|
24
|
-
setOnce(): ISubscribe<T>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type IOrderedOnce<T> = {
|
|
28
|
-
setOnce(): IOrderedSubscribe<T>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type ISetObservableValue = {
|
|
32
|
-
next(value: any): void;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type ISubscriptionLike<T> = {
|
|
36
|
-
unsubscribe(): void;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type ISetup<T> =
|
|
40
|
-
IUnsubscribeByNegative<T> &
|
|
41
|
-
IUnsubscribeByPositive<T> &
|
|
42
|
-
IEmitByNegative<T> &
|
|
43
|
-
IEmitByPositive<T> &
|
|
44
|
-
IEmitMatchCondition<T> &
|
|
45
|
-
IOnce<T> &
|
|
46
|
-
ISubscribe<T>;
|
|
47
|
-
|
|
48
|
-
export type IOrderedSetup<T> =
|
|
49
|
-
IOrderedUnsubscribeByNegative<T> &
|
|
50
|
-
IOrderedUnsubscribeByPositive<T> &
|
|
51
|
-
IOrderedEmitByNegative<T> &
|
|
52
|
-
IOrderedEmitByPositive<T> &
|
|
53
|
-
IOrderedEmitMatchCondition<T> &
|
|
54
|
-
IOrderedOnce<T> &
|
|
55
|
-
IOrderedSubscribe<T>;
|
|
56
|
-
|
|
57
|
-
export type ISubscribeObject<T> =
|
|
58
|
-
ISubscriptionLike<T> &
|
|
59
|
-
IPause &
|
|
60
|
-
IOrder &
|
|
61
|
-
ISend<T> &
|
|
62
|
-
ISetup<T>;
|
|
63
|
-
|
|
64
|
-
export type ISubscribeCounter = {
|
|
65
|
-
size(): number;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type ISubscriber<T> =
|
|
69
|
-
{
|
|
70
|
-
getValue(): T,
|
|
71
|
-
isEnable: boolean
|
|
72
|
-
} &
|
|
73
|
-
ISubscribe<T>;
|
|
74
|
-
|
|
75
|
-
export type IObserver<T> =
|
|
76
|
-
ISetObservableValue &
|
|
77
|
-
ISubscriber<T> &
|
|
78
|
-
IDestroy &
|
|
79
|
-
ISubscribeCounter &
|
|
80
|
-
IObservablePipe<T> &
|
|
81
|
-
{
|
|
82
|
-
unSubscribe(ISubscriptionLike): void,
|
|
83
|
-
unsubscribeAll(): void,
|
|
84
|
-
disable(): void,
|
|
85
|
-
enable(): void,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type IPause = {
|
|
89
|
-
pause(): void;
|
|
90
|
-
resume(): void;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type IObservablePipe<T> = {
|
|
94
|
-
pipe(): ISetup<T>
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export type ISend<T> = {
|
|
98
|
-
send(value: T): void;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export type IUnsubscribeByNegative<T> = {
|
|
102
|
-
unsubscribeByNegative(condition: ICallback<any>): ISubscribe<T>;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export type IOrderedUnsubscribeByNegative<T> = {
|
|
106
|
-
unsubscribeByNegative(condition: ICallback<any>): IOrderedSubscribe<T>;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type IUnsubscribeByPositive<T> = {
|
|
110
|
-
unsubscribeByPositive(condition: ICallback<any>): ISubscribe<T>;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export type IOrderedUnsubscribeByPositive<T> = {
|
|
114
|
-
unsubscribeByPositive(condition: ICallback<any>): IOrderedSubscribe<T>;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export type IEmitByNegative<T> = {
|
|
118
|
-
emitByNegative(condition: ICallback<any>): ISubscribe<T>;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export type IOrderedEmitByNegative<T> = {
|
|
122
|
-
emitByNegative(condition: ICallback<any>): IOrderedSubscribe<T>;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export type IEmitByPositive<T> = {
|
|
126
|
-
emitByPositive(condition: ICallback<any>): ISubscribe<T>;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export type IOrderedEmitByPositive<T> = {
|
|
130
|
-
emitByPositive(condition: ICallback<any>): IOrderedSubscribe<T>;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export type IEmitMatchCondition<T> = {
|
|
134
|
-
emitMatch(condition: ICallback<any>): ISubscribe<T>;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export type IOrderedEmitMatchCondition<T> = {
|
|
138
|
-
emitMatch(condition: ICallback<any>): IOrderedSubscribe<T>;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export type ICollector =
|
|
142
|
-
IDestroy &
|
|
143
|
-
ISubscribeCounter &
|
|
144
|
-
{
|
|
145
|
-
collect(...subscriptionLikeList: ISubscriptionLike<any>[]): void;
|
|
146
|
-
unsubscribe(subscriptionLike: ISubscriptionLike<any>): void;
|
|
147
|
-
unsubscribeAll(): void;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export type IOrderedObservable = {
|
|
151
|
-
sortByOrder(): void;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
export type IOrdered<T> = IObserver<T> & IOrderedObservable;
|
|
155
|
-
|
|
156
|
-
export type IOrderedSubscriptionLike<T> = ISubscriptionLike<T> & IOrder;
|
|
157
|
-
export type IOrderedSubscribe<T> = {
|
|
158
|
-
subscribe(listener: IListener<T>): IOrderedSubscriptionLike<T>;
|
|
159
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import {Observable} from "./Observables/Observable";
|
|
2
|
-
import {cb_function, delay_ms, delay_second, ITick, ITickListener} from "./Types";
|
|
3
|
-
import {ISubscriptionLike} from "./Observables/Types";
|
|
4
|
-
|
|
5
|
-
let listeners: ITickListener[] = [];
|
|
6
|
-
const tickDelay = 10;
|
|
7
|
-
let tickIndex = <any>0,
|
|
8
|
-
secondFPSIndex = <any>0,
|
|
9
|
-
optimizeCounter = 0,
|
|
10
|
-
optimizeNumber = 1000,
|
|
11
|
-
tick10$ = new Observable(<any>0),
|
|
12
|
-
tick100$ = new Observable(<any>0),
|
|
13
|
-
secondFPS$ = new Observable(<any>0),
|
|
14
|
-
tick1000$ = new Observable(<any>0);
|
|
15
|
-
|
|
16
|
-
class TickGenerator implements ITick {
|
|
17
|
-
private counter100 = 0;
|
|
18
|
-
private counter1000 = 0;
|
|
19
|
-
private isDestroyProcessed = false;
|
|
20
|
-
private _isDestroyed = false;
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
this.init();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private init(): void {
|
|
27
|
-
if (!secondFPSIndex) {
|
|
28
|
-
secondFPSIndex = setInterval(() => secondFPS$.next(-1), 1000);
|
|
29
|
-
}
|
|
30
|
-
if (!tickIndex) {
|
|
31
|
-
tickIndex = setInterval(() => {
|
|
32
|
-
this.counter100 += 10;
|
|
33
|
-
if (this.counter100 >= 100) this.counter100 = 0;
|
|
34
|
-
|
|
35
|
-
this.counter1000 += 10;
|
|
36
|
-
if (this.counter1000 >= 1000) this.counter1000 = 0;
|
|
37
|
-
|
|
38
|
-
tick10$.next(10);
|
|
39
|
-
if (!this.counter100) tick100$.next(100);
|
|
40
|
-
if (!this.counter1000) tick1000$.next(1000);
|
|
41
|
-
|
|
42
|
-
this.handleTimeOutListeners();
|
|
43
|
-
}, tickDelay);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
executeSecondInterval(cb: cb_function, time: delay_second): ISubscriptionLike<any> {
|
|
48
|
-
const number = time;
|
|
49
|
-
return tick1000$.subscribe(() => {
|
|
50
|
-
if (time > 0) time--;
|
|
51
|
-
|
|
52
|
-
if (!time) {
|
|
53
|
-
cb();
|
|
54
|
-
time = number;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
execute100MsInterval(cb: cb_function, time: delay_second): ISubscriptionLike<any> {
|
|
60
|
-
const number = time;
|
|
61
|
-
return tick100$.subscribe(() => {
|
|
62
|
-
if (time > 0) time--;
|
|
63
|
-
|
|
64
|
-
if (!time) {
|
|
65
|
-
cb();
|
|
66
|
-
time = number;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private handleTimeOutListeners(): void {
|
|
72
|
-
let isNeedToOptimize = false;
|
|
73
|
-
for (let i = 0; i < listeners.length; i++) {
|
|
74
|
-
const listener = listeners[i];
|
|
75
|
-
if (!listener) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (listener.isDestroy) {
|
|
79
|
-
listeners[i] = <any>0;
|
|
80
|
-
isNeedToOptimize = true;
|
|
81
|
-
} else {
|
|
82
|
-
if (listener.counter >= listener.delay) {
|
|
83
|
-
listener.callback();
|
|
84
|
-
listeners[i] = <any>0;
|
|
85
|
-
isNeedToOptimize = true;
|
|
86
|
-
} else {
|
|
87
|
-
listener.counter += tickDelay;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
this.optimizeKeys(isNeedToOptimize);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private optimizeKeys(isNeedToOptimize: boolean): void {
|
|
95
|
-
if (!isNeedToOptimize) return;
|
|
96
|
-
|
|
97
|
-
optimizeCounter++;
|
|
98
|
-
if (optimizeCounter < optimizeNumber) return;
|
|
99
|
-
|
|
100
|
-
optimizeCounter = 0;
|
|
101
|
-
const tmpListeners: ITickListener[] = [];
|
|
102
|
-
|
|
103
|
-
const length = listeners.length;
|
|
104
|
-
for (let i = 0; i < length; i++) if (listeners[i]) tmpListeners.push(listeners[i]);
|
|
105
|
-
|
|
106
|
-
listeners.length = 0;
|
|
107
|
-
listeners = tmpListeners;
|
|
108
|
-
tmpListeners.length = 0;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get isDestroyed(): boolean {
|
|
112
|
-
return this._isDestroyed;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
get tick10$(): Observable<any> {
|
|
116
|
-
return tick10$;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get tick100$(): Observable<any> {
|
|
120
|
-
return tick100$;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get tick1000$(): Observable<any> {
|
|
124
|
-
return tick1000$;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
get secondFPS$(): Observable<any> {
|
|
128
|
-
return secondFPS$;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
executeTimeout(cb: cb_function, time: delay_ms): ITickListener {
|
|
132
|
-
const listener: ITickListener = {
|
|
133
|
-
counter: 0,
|
|
134
|
-
delay: time,
|
|
135
|
-
callback: cb,
|
|
136
|
-
isDestroy: false
|
|
137
|
-
};
|
|
138
|
-
listeners.push(listener);
|
|
139
|
-
return listener;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
clearTimeout(id: ITickListener): void {
|
|
143
|
-
if (!id) return;
|
|
144
|
-
|
|
145
|
-
id.isDestroy = true;
|
|
146
|
-
id.callback = () => console.log('listener has been destroyed');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
destroy(): void {
|
|
150
|
-
if (this.isDestroyProcessed) return;
|
|
151
|
-
this.isDestroyProcessed = true;
|
|
152
|
-
|
|
153
|
-
this.counter100 = 0;
|
|
154
|
-
this.counter1000 = 0;
|
|
155
|
-
clearInterval(tickIndex);
|
|
156
|
-
clearInterval(secondFPSIndex);
|
|
157
|
-
tickIndex = <any>0;
|
|
158
|
-
secondFPSIndex = <any>0;
|
|
159
|
-
|
|
160
|
-
this.resetListeners(tick10$);
|
|
161
|
-
this.resetListeners(tick100$);
|
|
162
|
-
this.resetListeners(tick1000$);
|
|
163
|
-
this.resetListeners(secondFPS$);
|
|
164
|
-
|
|
165
|
-
tick10$ = <any>0;
|
|
166
|
-
tick100$ = <any>0;
|
|
167
|
-
tick1000$ = <any>0;
|
|
168
|
-
secondFPS$ = <any>0;
|
|
169
|
-
|
|
170
|
-
this._isDestroyed = true;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private resetListeners(observable: Observable<any>): void {
|
|
174
|
-
if (observable) observable.unsubscribeAll();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export const tickGenerator = new TickGenerator();
|
package/src/Libraries/Types.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {Observable} from "./Observables/Observable";
|
|
2
|
-
import {ISubscriptionLike} from "./Observables/Types";
|
|
3
|
-
|
|
4
|
-
export type IDestroyed = {
|
|
5
|
-
isDestroyed: boolean;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type delay_ms = number;
|
|
9
|
-
export type delay_second = number;
|
|
10
|
-
export type cb_function = () => void;
|
|
11
|
-
export type ITickListener = {
|
|
12
|
-
counter: number;
|
|
13
|
-
delay: delay_ms;
|
|
14
|
-
callback: cb_function;
|
|
15
|
-
isDestroy: boolean;
|
|
16
|
-
};
|
|
17
|
-
export type ITick = {
|
|
18
|
-
tick10$: Observable<any>;
|
|
19
|
-
tick100$: Observable<any>;
|
|
20
|
-
tick1000$: Observable<any>;
|
|
21
|
-
secondFPS$: Observable<any>;
|
|
22
|
-
executeTimeout(cb: cb_function, time: delay_ms): ITickListener;
|
|
23
|
-
execute100MsInterval(cb: cb_function, time: number): ISubscriptionLike<number>;
|
|
24
|
-
executeSecondInterval(cb: cb_function, time: delay_second): ISubscriptionLike<number>;
|
|
25
|
-
clearTimeout(id: ITickListener): void;
|
|
26
|
-
destroy(): void;
|
|
27
|
-
} & IDestroyed;
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import {suite, test} from '@testdeck/mocha';
|
|
2
|
-
import * as _chai from 'chai';
|
|
3
|
-
import {expect} from 'chai';
|
|
4
|
-
import {ICollector} from "../src/Libraries/Observables/Types";
|
|
5
|
-
import {Collector} from "../src/Libraries/Observables/Collector";
|
|
6
|
-
import {Observable} from "../src/Libraries/Observables/Observable";
|
|
7
|
-
|
|
8
|
-
_chai.should();
|
|
9
|
-
_chai.expect;
|
|
10
|
-
|
|
11
|
-
@suite
|
|
12
|
-
class CollectorUnitTest {
|
|
13
|
-
private COLLECTOR: ICollector;
|
|
14
|
-
|
|
15
|
-
before() {
|
|
16
|
-
this.COLLECTOR = new Collector();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@test 'collector is created'() {
|
|
20
|
-
expect(this.COLLECTOR.size()).to.be.eql(0);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@test 'collector collect one subscriber'() {
|
|
24
|
-
const observable$ = new Observable(0);
|
|
25
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
26
|
-
expect(this.COLLECTOR.size()).to.be.equal(1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@test 'collector collect two subscribers'() {
|
|
30
|
-
const observable$ = new Observable(0);
|
|
31
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
32
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
33
|
-
expect(this.COLLECTOR.size()).to.be.equal(2);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@test 'collector collect three subscribers'() {
|
|
37
|
-
const observable$ = new Observable(0);
|
|
38
|
-
this.COLLECTOR.collect(
|
|
39
|
-
observable$.subscribe(value => value),
|
|
40
|
-
observable$.subscribe(value => value),
|
|
41
|
-
observable$.subscribe(value => value),
|
|
42
|
-
);
|
|
43
|
-
expect(this.COLLECTOR.size()).to.be.equal(3);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@test 'collector collect ten subscribers'() {
|
|
47
|
-
const observable$ = new Observable(0);
|
|
48
|
-
for (let i = 0; i < 10; i++) {
|
|
49
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
50
|
-
}
|
|
51
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@test 'collector collect zero subscribers'() {
|
|
55
|
-
this.COLLECTOR.collect();
|
|
56
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
@test 'collector collect one subscriber and unsubscribe'() {
|
|
60
|
-
const observable$ = new Observable(0);
|
|
61
|
-
const subscriptionLike = observable$.subscribe(value => value);
|
|
62
|
-
this.COLLECTOR.collect(subscriptionLike);
|
|
63
|
-
expect(this.COLLECTOR.size()).to.be.equal(1);
|
|
64
|
-
this.COLLECTOR.unsubscribe(subscriptionLike);
|
|
65
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@test 'collector collect one subscriber and unsubscribe all'() {
|
|
69
|
-
const observable$ = new Observable(0);
|
|
70
|
-
const subscriptionLike = observable$.subscribe(value => value);
|
|
71
|
-
this.COLLECTOR.collect(subscriptionLike);
|
|
72
|
-
expect(this.COLLECTOR.size()).to.be.equal(1);
|
|
73
|
-
this.COLLECTOR.unsubscribeAll();
|
|
74
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@test 'collector collect zero subscribers and unsubscribe'() {
|
|
78
|
-
const observable$ = new Observable(0);
|
|
79
|
-
const subscriptionLike = observable$.subscribe(value => value);
|
|
80
|
-
this.COLLECTOR.collect();
|
|
81
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
82
|
-
this.COLLECTOR.unsubscribe(subscriptionLike);
|
|
83
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
84
|
-
expect((<any>subscriptionLike).observable).to.be.equal(0);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@test 'collector collect zero subscribers and unsubscribeAll'() {
|
|
88
|
-
const observable$ = new Observable(0);
|
|
89
|
-
const subscriptionLike = observable$.subscribe(value => value);
|
|
90
|
-
this.COLLECTOR.collect();
|
|
91
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
92
|
-
this.COLLECTOR.unsubscribeAll();
|
|
93
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
94
|
-
expect(!!(<any>subscriptionLike).observable).to.be.equal(true);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@test 'collector collect two subscribers and unsubscribe one'() {
|
|
98
|
-
const observable$ = new Observable(0);
|
|
99
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
100
|
-
const subscriptionLike2 = observable$.subscribe(value => value);
|
|
101
|
-
this.COLLECTOR.collect(subscriptionLike1, subscriptionLike2);
|
|
102
|
-
expect(this.COLLECTOR.size()).to.be.equal(2);
|
|
103
|
-
this.COLLECTOR.unsubscribe(subscriptionLike1);
|
|
104
|
-
expect(this.COLLECTOR.size()).to.be.equal(1);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@test 'collector collect two subscribers and unsubscribe two'() {
|
|
108
|
-
const observable$ = new Observable(0);
|
|
109
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
110
|
-
const subscriptionLike2 = observable$.subscribe(value => value);
|
|
111
|
-
this.COLLECTOR.collect(subscriptionLike1, subscriptionLike2);
|
|
112
|
-
expect(this.COLLECTOR.size()).to.be.equal(2);
|
|
113
|
-
this.COLLECTOR.unsubscribe(subscriptionLike1);
|
|
114
|
-
this.COLLECTOR.unsubscribe(subscriptionLike2);
|
|
115
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@test 'collector collect two subscribers and unsubscribe all'() {
|
|
119
|
-
const observable$ = new Observable(0);
|
|
120
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
121
|
-
const subscriptionLike2 = observable$.subscribe(value => value);
|
|
122
|
-
this.COLLECTOR.collect(subscriptionLike1, subscriptionLike2);
|
|
123
|
-
expect(this.COLLECTOR.size()).to.be.equal(2);
|
|
124
|
-
this.COLLECTOR.unsubscribeAll();
|
|
125
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@test 'collector collect ten subscribers and unsubscribe one'() {
|
|
129
|
-
const observable$ = new Observable(0);
|
|
130
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
131
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
132
|
-
for (let i = 0; i < 9; i++) {
|
|
133
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
134
|
-
}
|
|
135
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
136
|
-
this.COLLECTOR.unsubscribe(subscriptionLike1);
|
|
137
|
-
expect(this.COLLECTOR.size()).to.be.equal(9);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@test 'collector collect ten subscribers and unsubscribe two'() {
|
|
141
|
-
const observable$ = new Observable(0);
|
|
142
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
143
|
-
const subscriptionLike2 = observable$.subscribe(value => value);
|
|
144
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
145
|
-
this.COLLECTOR.collect(subscriptionLike2);
|
|
146
|
-
for (let i = 0; i < 8; i++) {
|
|
147
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
148
|
-
}
|
|
149
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
150
|
-
this.COLLECTOR.unsubscribe(subscriptionLike1);
|
|
151
|
-
this.COLLECTOR.unsubscribe(subscriptionLike2);
|
|
152
|
-
expect(this.COLLECTOR.size()).to.be.equal(8);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
@test 'collector collect ten subscribers and unsubscribe all'() {
|
|
156
|
-
const observable$ = new Observable(0);
|
|
157
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
158
|
-
const subscriptionLike2 = observable$.subscribe(value => value);
|
|
159
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
160
|
-
this.COLLECTOR.collect(subscriptionLike2);
|
|
161
|
-
for (let i = 0; i < 8; i++) {
|
|
162
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
163
|
-
}
|
|
164
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
165
|
-
this.COLLECTOR.unsubscribeAll();
|
|
166
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
@test 'collector collect one subscriber and destroy'() {
|
|
170
|
-
const observable$ = new Observable(0);
|
|
171
|
-
const subscriptionLike = observable$.subscribe(value => value);
|
|
172
|
-
this.COLLECTOR.collect(subscriptionLike);
|
|
173
|
-
expect(this.COLLECTOR.size()).to.be.equal(1);
|
|
174
|
-
this.COLLECTOR.destroy();
|
|
175
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
176
|
-
expect(this.COLLECTOR.isDestroyed).to.be.equal(true);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
@test 'collector collect two subscribers and destroy'() {
|
|
180
|
-
const observable$ = new Observable(0);
|
|
181
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
182
|
-
const subscriptionLike2 = observable$.subscribe(value => value);
|
|
183
|
-
this.COLLECTOR.collect(subscriptionLike1, subscriptionLike2);
|
|
184
|
-
expect(this.COLLECTOR.size()).to.be.equal(2);
|
|
185
|
-
this.COLLECTOR.destroy();
|
|
186
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
187
|
-
expect(this.COLLECTOR.isDestroyed).to.be.equal(true);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@test 'collector collect ten subscribers and destroy'() {
|
|
191
|
-
const observable$ = new Observable(0);
|
|
192
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
193
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
194
|
-
for (let i = 0; i < 9; i++) {
|
|
195
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
196
|
-
}
|
|
197
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
198
|
-
this.COLLECTOR.destroy();
|
|
199
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
200
|
-
expect(this.COLLECTOR.isDestroyed).to.be.equal(true);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@test 'collector collect ten subscribers, destroy and collect '() {
|
|
204
|
-
const observable$ = new Observable(0);
|
|
205
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
206
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
207
|
-
for (let i = 0; i < 9; i++) {
|
|
208
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
209
|
-
}
|
|
210
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
211
|
-
this.COLLECTOR.destroy();
|
|
212
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
213
|
-
expect(this.COLLECTOR.isDestroyed).to.be.equal(true);
|
|
214
|
-
expect(this.COLLECTOR.collect()).to.be.equal(null);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
@test 'collector collect ten subscribers, destroy and unsubscribe '() {
|
|
218
|
-
const observable$ = new Observable(0);
|
|
219
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
220
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
221
|
-
for (let i = 0; i < 9; i++) {
|
|
222
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
223
|
-
}
|
|
224
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
225
|
-
this.COLLECTOR.destroy();
|
|
226
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
227
|
-
expect(this.COLLECTOR.isDestroyed).to.be.equal(true);
|
|
228
|
-
expect(this.COLLECTOR.unsubscribe(subscriptionLike1)).to.be.equal(null);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
@test 'collector collect ten subscribers, destroy and unsubscribeAll '() {
|
|
232
|
-
const observable$ = new Observable(0);
|
|
233
|
-
const subscriptionLike1 = observable$.subscribe(value => value);
|
|
234
|
-
this.COLLECTOR.collect(subscriptionLike1);
|
|
235
|
-
for (let i = 0; i < 9; i++) {
|
|
236
|
-
this.COLLECTOR.collect(observable$.subscribe(value => value));
|
|
237
|
-
}
|
|
238
|
-
expect(this.COLLECTOR.size()).to.be.equal(10);
|
|
239
|
-
this.COLLECTOR.destroy();
|
|
240
|
-
expect(this.COLLECTOR.size()).to.be.equal(0);
|
|
241
|
-
expect(this.COLLECTOR.isDestroyed).to.be.equal(true);
|
|
242
|
-
expect(this.COLLECTOR.unsubscribeAll()).to.be.equal(null);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {suite, test} from '@testdeck/mocha';
|
|
2
|
-
import * as _chai from 'chai';
|
|
3
|
-
import {expect} from 'chai';
|
|
4
|
-
import {deleteFromArray} from "../src/Libraries/FunctionLibs";
|
|
5
|
-
|
|
6
|
-
_chai.should();
|
|
7
|
-
_chai.expect;
|
|
8
|
-
|
|
9
|
-
@suite
|
|
10
|
-
class FunctionLibUnitTest {
|
|
11
|
-
private deleteFromArray: <T>(arr: T[], component: T) => boolean;
|
|
12
|
-
|
|
13
|
-
before() {
|
|
14
|
-
this.deleteFromArray = deleteFromArray;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@test 'deleteFromArray: 1 from arr empty'() {
|
|
18
|
-
expect(this.deleteFromArray([], 1)).to.be.equal(false);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@test 'deleteFromArray: 1 from arr [1]'() {
|
|
22
|
-
const arr = [1];
|
|
23
|
-
expect(this.deleteFromArray(arr, 1)).to.be.equal(true);
|
|
24
|
-
expect(arr).to.be.eql([]);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@test 'deleteFromArray: 1 from arr [1, 2]'() {
|
|
28
|
-
const arr = [1, 2];
|
|
29
|
-
expect(this.deleteFromArray(arr, 1)).to.be.equal(true);
|
|
30
|
-
expect(arr).to.be.eql([2]);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@test 'deleteFromArray: 2 from arr [1, 2]'() {
|
|
34
|
-
const arr = [1, 2];
|
|
35
|
-
expect(this.deleteFromArray(arr, 2)).to.be.equal(true);
|
|
36
|
-
expect(arr).to.be.eql([1]);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@test 'deleteFromArray: 1 from arr [1, 2, 3]'() {
|
|
40
|
-
const arr = [1, 2, 3];
|
|
41
|
-
expect(this.deleteFromArray(arr, 1)).to.be.equal(true);
|
|
42
|
-
expect(arr).to.be.eql([2, 3]);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@test 'deleteFromArray: 2 from arr [1, 2, 3]'() {
|
|
46
|
-
const arr = [1, 2, 3];
|
|
47
|
-
expect(this.deleteFromArray(arr, 2)).to.be.equal(true);
|
|
48
|
-
expect(arr).to.be.eql([1, 3]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@test 'deleteFromArray: 3 from arr [1, 2, 3]'() {
|
|
52
|
-
const arr = [1, 2, 3];
|
|
53
|
-
expect(this.deleteFromArray(arr, 3)).to.be.equal(true);
|
|
54
|
-
expect(arr).to.be.eql([1, 2]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@test 'deleteFromArray: 4 from arr [1, 2, 3]'() {
|
|
58
|
-
const arr = [1, 2, 3];
|
|
59
|
-
expect(this.deleteFromArray(arr, 4)).to.be.equal(false);
|
|
60
|
-
expect(arr).to.be.eql([1, 2, 3]);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@test 'deleteFromArray: 1 from arr [1, 1, 2, 3]'() {
|
|
64
|
-
const arr = [1, 1, 2, 3];
|
|
65
|
-
expect(this.deleteFromArray(arr, 1)).to.be.equal(true);
|
|
66
|
-
expect(arr).to.be.eql([1, 2, 3]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@test 'deleteFromArray: 2 from arr [1, 1, 2, 3]'() {
|
|
70
|
-
const arr = [1, 1, 2, 3];
|
|
71
|
-
expect(this.deleteFromArray(arr, 2)).to.be.equal(true);
|
|
72
|
-
expect(arr).to.be.eql([1, 1, 3]);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@test 'deleteFromArray: 3 from arr [1, 1, 2, 3]'() {
|
|
76
|
-
const arr = [1, 1, 2, 3];
|
|
77
|
-
expect(this.deleteFromArray(arr, 3)).to.be.equal(true);
|
|
78
|
-
expect(arr).to.be.eql([1, 1, 2]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@test 'deleteFromArray: 4 from arr [1, 1, 2, 3]'() {
|
|
82
|
-
const arr = [1, 1, 2, 3];
|
|
83
|
-
expect(this.deleteFromArray(arr, 4)).to.be.equal(false);
|
|
84
|
-
expect(arr).to.be.eql([1, 1, 2, 3]);
|
|
85
|
-
}
|
|
86
|
-
}
|