-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
55 lines (43 loc) · 1.24 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* tslint:disable:no-console */
import 'rxjs/add/observable/timer';
import 'rxjs/add/operator/pluck';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/timeInterval';
import { Observable } from 'rxjs/Observable';
import { SubscriptionPool } from './subscription-pool';
// import { propertyDecorator } from './decorator';
const source$ = Observable.timer(200, 100)
.timeInterval()
.pluck('interval')
.take(100);
interface IComponent {
ngOnInit: () => void;
ngOnDestroy: () => void;
}
class DecoratorTest implements IComponent {
// @propertyDecorator
private isLoading = true;
@SubscriptionPool private subscriptions;
constructor(private name: string) {
console.log(this.isLoading);
this.isLoading = true;
this.ngOnInit();
setTimeout(() => {
this.ngOnDestroy();
}, 2000);
}
public doStuff() {
this.subscriptions.add(source$.subscribe(x => console.log(this.name, x)));
}
public ngOnInit() {
this.isLoading = false;
console.log('original onInit', this.name);
}
public ngOnDestroy() {
console.log('original ngOnDestroy', this.name);
}
}
const decoratorTestA = new DecoratorTest('A');
decoratorTestA.doStuff();
const decoratorTestB = new DecoratorTest('B');
decoratorTestB.doStuff();