refactor(core): collect lifecycle hooks for all injectable classes
This commit is contained in:
@ -109,7 +109,7 @@ export class CompileElement extends CompileNode {
|
||||
// ProviderAstType.PrivateService as only the component and its view can see it,
|
||||
// but nobody else
|
||||
this._resolvedProvidersArray.unshift(new ProviderAst(
|
||||
provider.token, false, true, [provider], ProviderAstType.PrivateService,
|
||||
provider.token, false, true, [provider], ProviderAstType.PrivateService, [],
|
||||
this.sourceAst.sourceSpan));
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ export class CompileElement extends CompileNode {
|
||||
{token: identifierToken(Identifiers.TemplateRef), useValue: createTemplateRefExpr});
|
||||
// Add TemplateRef as first provider as it does not have deps on other providers
|
||||
this._resolvedProvidersArray.unshift(new ProviderAst(
|
||||
provider.token, false, true, [provider], ProviderAstType.Builtin,
|
||||
provider.token, false, true, [provider], ProviderAstType.Builtin, [],
|
||||
this.sourceAst.sourceSpan));
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ export function bindDirectiveDetectChangesLifecycleCallbacks(
|
||||
directiveAst: DirectiveAst, directiveInstance: o.Expression, compileElement: CompileElement) {
|
||||
var view = compileElement.view;
|
||||
var detectChangesInInputsMethod = view.detectChangesInInputsMethod;
|
||||
var lifecycleHooks = directiveAst.directive.lifecycleHooks;
|
||||
var lifecycleHooks = directiveAst.directive.type.lifecycleHooks;
|
||||
if (lifecycleHooks.indexOf(LifecycleHooks.OnChanges) !== -1 && directiveAst.inputs.length > 0) {
|
||||
detectChangesInInputsMethod.addStmt(new o.IfStmt(
|
||||
DetectChangesVars.changes.notIdentical(o.NULL_EXPR),
|
||||
@ -45,7 +45,7 @@ export function bindDirectiveAfterContentLifecycleCallbacks(
|
||||
directiveMeta: CompileDirectiveMetadata, directiveInstance: o.Expression,
|
||||
compileElement: CompileElement) {
|
||||
var view = compileElement.view;
|
||||
var lifecycleHooks = directiveMeta.lifecycleHooks;
|
||||
var lifecycleHooks = directiveMeta.type.lifecycleHooks;
|
||||
var afterContentLifecycleCallbacksMethod = view.afterContentLifecycleCallbacksMethod;
|
||||
afterContentLifecycleCallbacksMethod.resetDebugInfo(
|
||||
compileElement.nodeIndex, compileElement.sourceAst);
|
||||
@ -63,7 +63,7 @@ export function bindDirectiveAfterViewLifecycleCallbacks(
|
||||
directiveMeta: CompileDirectiveMetadata, directiveInstance: o.Expression,
|
||||
compileElement: CompileElement) {
|
||||
var view = compileElement.view;
|
||||
var lifecycleHooks = directiveMeta.lifecycleHooks;
|
||||
var lifecycleHooks = directiveMeta.type.lifecycleHooks;
|
||||
var afterViewLifecycleCallbacksMethod = view.afterViewLifecycleCallbacksMethod;
|
||||
afterViewLifecycleCallbacksMethod.resetDebugInfo(
|
||||
compileElement.nodeIndex, compileElement.sourceAst);
|
||||
@ -82,7 +82,7 @@ export function bindDirectiveDestroyLifecycleCallbacks(
|
||||
compileElement: CompileElement) {
|
||||
var onDestroyMethod = compileElement.view.destroyMethod;
|
||||
onDestroyMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
|
||||
if (directiveMeta.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
|
||||
if (directiveMeta.type.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
|
||||
onDestroyMethod.addStmt(directiveInstance.callMethod('ngOnDestroy', []).toStmt());
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ export function bindDirectiveDestroyLifecycleCallbacks(
|
||||
export function bindPipeDestroyLifecycleCallbacks(
|
||||
pipeMeta: CompilePipeMetadata, pipeInstance: o.Expression, view: CompileView) {
|
||||
var onDestroyMethod = view.destroyMethod;
|
||||
if (pipeMeta.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
|
||||
if (pipeMeta.type.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
|
||||
onDestroyMethod.addStmt(pipeInstance.callMethod('ngOnDestroy', []).toStmt());
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ export function bindDirectiveInputs(
|
||||
var detectChangesInInputsMethod = view.detectChangesInInputsMethod;
|
||||
detectChangesInInputsMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
|
||||
|
||||
var lifecycleHooks = directiveAst.directive.lifecycleHooks;
|
||||
var lifecycleHooks = directiveAst.directive.type.lifecycleHooks;
|
||||
var calcChangesMap = lifecycleHooks.indexOf(LifecycleHooks.OnChanges) !== -1;
|
||||
var isOnPushComp = directiveAst.directive.isComponent &&
|
||||
!isDefaultChangeDetectionStrategy(directiveAst.directive.changeDetection);
|
||||
|
Reference in New Issue
Block a user