-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
33 lines (25 loc) · 1.05 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
import { Subject } from 'rxjs';
import { MonoTypeOperatorFunction } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
const metaProperty = Symbol();
let aot = true;
export function ngxRxCollectorDisableAoTWarning() {
aot = false;
}
export function untilDestroyed<T>(componentInstance: any, destructorName = 'ngOnDestroy'): MonoTypeOperatorFunction<T> {
if (!componentInstance[metaProperty]) {
const originalDestructor = componentInstance[destructorName];
if (!originalDestructor && aot) {
console.warn('untilDestroyed limitation: ngOnDestroy is not present on the component which is a problem for AoT. See https://github.com/angular/angular/issues/16023 for more details');
}
componentInstance[metaProperty] = new Subject();
componentInstance[destructorName] = function() {
if (originalDestructor) {
originalDestructor.call(componentInstance);
}
componentInstance[metaProperty].next();
componentInstance[metaProperty].complete();
};
}
return takeUntil(componentInstance[metaProperty]);
}