File tree Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Original file line number Diff line number Diff line change 1
- import { ISubscription } from '../types/core/ISubscription'
2
1
/**
3
2
* Created by tushar.mathur on 12/10/16.
4
3
*/
5
4
5
+ import { ISubscription } from '../types/core/ISubscription'
6
+ import { LinkedList , Node } from './LinkedList'
6
7
7
- const propClosed = ( x : ISubscription ) => x . closed
8
+ const unsubscribe = ( x : ISubscription ) => x . unsubscribe ( )
8
9
9
10
export class CompositeSubscription implements ISubscription {
10
- constructor ( private subscriptions : ISubscription [ ] = [ ] ) {
11
+ public closed = false
12
+ private subscriptions : LinkedList < ISubscription >
13
+
14
+ constructor ( ) {
15
+ this . subscriptions = new LinkedList < ISubscription > ( )
11
16
}
12
17
13
18
add ( d : ISubscription ) {
14
- this . subscriptions . push ( d )
19
+ return this . subscriptions . add ( d )
15
20
}
16
21
17
- unsubscribe ( ) : void {
18
- for ( var i = 0 ; i < this . subscriptions . length ; i ++ ) {
19
- this . subscriptions [ i ] . unsubscribe ( )
20
- }
22
+ remove ( d : Node < ISubscription > ) {
23
+ d . value . unsubscribe ( )
24
+ return this . subscriptions . remove ( d )
21
25
}
22
26
23
- get closed ( ) : boolean {
24
- return this . subscriptions . map ( propClosed ) . every ( Boolean )
27
+ unsubscribe ( ) : void {
28
+ this . subscriptions . forEach ( unsubscribe )
29
+ this . closed = true
25
30
}
26
31
}
Original file line number Diff line number Diff line change 4
4
5
5
6
6
export class Node < T > {
7
- public left : Node < T > | null
8
- public right : Node < T > | null
7
+ public left : Node < T > | undefined
8
+ public right : Node < T > | undefined
9
9
10
10
constructor ( public value : T ) {
11
- this . right = null
12
- this . left = null
11
+ this . right = undefined
12
+ this . left = undefined
13
13
}
14
14
15
15
static of < T > ( val : T ) {
@@ -19,11 +19,11 @@ export class Node<T> {
19
19
20
20
export class LinkedList < T > {
21
21
public length : number
22
- private __head : Node < T > | null
22
+ private __head : Node < T > | undefined
23
23
24
24
constructor ( ) {
25
25
this . length = 0
26
- this . __head = null
26
+ this . __head = undefined
27
27
}
28
28
29
29
element ( ) {
@@ -58,12 +58,12 @@ export class LinkedList<T> {
58
58
}
59
59
else if ( n . left ) {
60
60
this . __head = n . left
61
- n . left . right = null
61
+ n . left . right = undefined
62
62
}
63
63
else if ( n . right ) {
64
- n . right . left = null
64
+ n . right . left = undefined
65
65
} else {
66
- this . __head = null
66
+ this . __head = undefined
67
67
}
68
68
this . length --
69
69
}
You can’t perform that action at this time.
0 commit comments