refactor(compiler): don’t rely on global reflector (#16832)
Using the global reflector made it impossible to compile multiple programs at the same time.
This commit is contained in:

committed by
Chuck Jazdzewski

parent
de8d7c65f2
commit
50abca4583
@ -6,30 +6,51 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ɵLifecycleHooks, ɵreflector} from '@angular/core';
|
||||
import {CompileReflector} from './compile_reflector';
|
||||
|
||||
|
||||
export function hasLifecycleHook(hook: ɵLifecycleHooks, token: any): boolean {
|
||||
return ɵreflector.hasLifecycleHook(token, getHookName(hook));
|
||||
export enum LifecycleHooks {
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
DoCheck,
|
||||
OnChanges,
|
||||
AfterContentInit,
|
||||
AfterContentChecked,
|
||||
AfterViewInit,
|
||||
AfterViewChecked
|
||||
}
|
||||
|
||||
function getHookName(hook: ɵLifecycleHooks): string {
|
||||
export const LIFECYCLE_HOOKS_VALUES = [
|
||||
LifecycleHooks.OnInit, LifecycleHooks.OnDestroy, LifecycleHooks.DoCheck, LifecycleHooks.OnChanges,
|
||||
LifecycleHooks.AfterContentInit, LifecycleHooks.AfterContentChecked, LifecycleHooks.AfterViewInit,
|
||||
LifecycleHooks.AfterViewChecked
|
||||
];
|
||||
|
||||
export function hasLifecycleHook(
|
||||
reflector: CompileReflector, hook: LifecycleHooks, token: any): boolean {
|
||||
return reflector.hasLifecycleHook(token, getHookName(hook));
|
||||
}
|
||||
|
||||
export function getAllLifecycleHooks(reflector: CompileReflector, token: any): LifecycleHooks[] {
|
||||
return LIFECYCLE_HOOKS_VALUES.filter(hook => hasLifecycleHook(reflector, hook, token));
|
||||
}
|
||||
|
||||
function getHookName(hook: LifecycleHooks): string {
|
||||
switch (hook) {
|
||||
case ɵLifecycleHooks.OnInit:
|
||||
case LifecycleHooks.OnInit:
|
||||
return 'ngOnInit';
|
||||
case ɵLifecycleHooks.OnDestroy:
|
||||
case LifecycleHooks.OnDestroy:
|
||||
return 'ngOnDestroy';
|
||||
case ɵLifecycleHooks.DoCheck:
|
||||
case LifecycleHooks.DoCheck:
|
||||
return 'ngDoCheck';
|
||||
case ɵLifecycleHooks.OnChanges:
|
||||
case LifecycleHooks.OnChanges:
|
||||
return 'ngOnChanges';
|
||||
case ɵLifecycleHooks.AfterContentInit:
|
||||
case LifecycleHooks.AfterContentInit:
|
||||
return 'ngAfterContentInit';
|
||||
case ɵLifecycleHooks.AfterContentChecked:
|
||||
case LifecycleHooks.AfterContentChecked:
|
||||
return 'ngAfterContentChecked';
|
||||
case ɵLifecycleHooks.AfterViewInit:
|
||||
case LifecycleHooks.AfterViewInit:
|
||||
return 'ngAfterViewInit';
|
||||
case ɵLifecycleHooks.AfterViewChecked:
|
||||
case LifecycleHooks.AfterViewChecked:
|
||||
return 'ngAfterViewChecked';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user