refactor(upgrade): allow Closure advanced optimizations in `UpgradeComponent` (#13629)
Get rid of the dynamic invocation style used in `callLifecycleHook()`, which would break under Closure Compiler's advanced optimizations. Related to https://github.com/angular/angular/pull/13020#discussion_r93492935. PR Close #13629
This commit is contained in:
parent
a277e97dd7
commit
00979838ef
|
@ -167,10 +167,12 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
|||
});
|
||||
}
|
||||
|
||||
this.callLifecycleHook('$onInit', this.controllerInstance);
|
||||
if (this.controllerInstance && isFunction(this.controllerInstance.$onInit)) {
|
||||
this.controllerInstance.$onInit();
|
||||
}
|
||||
|
||||
if (this.controllerInstance && isFunction(this.controllerInstance.$doCheck)) {
|
||||
const callDoCheck = () => this.callLifecycleHook('$doCheck', this.controllerInstance);
|
||||
const callDoCheck = () => this.controllerInstance.$doCheck();
|
||||
|
||||
this.$componentScope.$parent.$watch(callDoCheck);
|
||||
callDoCheck();
|
||||
|
@ -200,7 +202,9 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
|||
postLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
||||
}
|
||||
|
||||
this.callLifecycleHook('$postLink', this.controllerInstance);
|
||||
if (this.controllerInstance && isFunction(this.controllerInstance.$postLink)) {
|
||||
this.controllerInstance.$postLink();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
|
@ -208,7 +212,9 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
|||
Object.keys(changes).forEach(
|
||||
propName => this.bindingDestination[propName] = changes[propName].currentValue);
|
||||
|
||||
this.callLifecycleHook('$onChanges', this.bindingDestination, changes);
|
||||
if (isFunction(this.bindingDestination.$onChanges)) {
|
||||
this.bindingDestination.$onChanges(changes);
|
||||
}
|
||||
}
|
||||
|
||||
ngDoCheck() {
|
||||
|
@ -231,16 +237,12 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
|||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.callLifecycleHook('$onDestroy', this.controllerInstance);
|
||||
if (this.controllerInstance && isFunction(this.controllerInstance.$onDestroy)) {
|
||||
this.controllerInstance.$onDestroy();
|
||||
}
|
||||
this.$componentScope.$destroy();
|
||||
}
|
||||
|
||||
private callLifecycleHook(method: LifecycleHook, context: IBindingDestination, arg?: any) {
|
||||
if (context && isFunction(context[method])) {
|
||||
context[method](arg);
|
||||
}
|
||||
}
|
||||
|
||||
private getDirective(name: string): angular.IDirective {
|
||||
const directives: angular.IDirective[] = this.$injector.get(name + 'Directive');
|
||||
if (directives.length > 1) {
|
||||
|
|
Loading…
Reference in New Issue