refactor(ivy): flatten hooks and collapse LView hook properties (#21650)
PR Close #21650
This commit is contained in:

committed by
Misko Hevery

parent
33b338120c
commit
3e03dbe576
@ -71,14 +71,16 @@ export interface DirectiveDef<T> {
|
||||
* Refreshes host bindings on the associated directive. Also calls lifecycle hooks
|
||||
* like ngOnInit and ngDoCheck, if they are defined on the directive.
|
||||
*/
|
||||
// Note: This call must be separate from r() because hooks like ngOnInit need to
|
||||
// be called breadth-first across a view before processing onInits in children
|
||||
// (for backwards compatibility). Child template processing thus needs to be
|
||||
// delayed until all inputs and host bindings in a view have been checked.
|
||||
h(directiveIndex: number, elementIndex: number): void;
|
||||
|
||||
/* A map of the lifecycle hooks defined on this directive (key: name, value: fn) */
|
||||
lifecycleHooks: LifecycleHooksMap;
|
||||
/* The following are lifecycle hooks for this component */
|
||||
onInit: (() => void)|null;
|
||||
doCheck: (() => void)|null;
|
||||
afterContentInit: (() => void)|null;
|
||||
afterContentChecked: (() => void)|null;
|
||||
afterViewInit: (() => void)|null;
|
||||
afterViewChecked: (() => void)|null;
|
||||
onDestroy: (() => void)|null;
|
||||
}
|
||||
|
||||
export interface ComponentDef<T> extends DirectiveDef<T> {
|
||||
@ -104,17 +106,6 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
|
||||
readonly rendererType: RendererType2|null;
|
||||
}
|
||||
|
||||
/* A map of the lifecycle hooks defined on a directive (key: name, value: fn) */
|
||||
export interface LifecycleHooksMap {
|
||||
onInit: () => void | null;
|
||||
doCheck: () => void | null;
|
||||
afterContentInit: () => void | null;
|
||||
afterContentChecked: () => void | null;
|
||||
afterViewInit: () => void | null;
|
||||
afterViewChecked: () => void | null;
|
||||
onDestroy: () => void | null;
|
||||
}
|
||||
|
||||
export interface DirectiveDefArgs<T> {
|
||||
type: Type<T>;
|
||||
factory: () => T;
|
||||
|
@ -88,24 +88,21 @@ export interface LView {
|
||||
cleanup: any[]|null;
|
||||
|
||||
/**
|
||||
* Whether or not the ngOnInit and ngDoCheck hooks have been called in this change
|
||||
* detection run.
|
||||
* This number tracks the next lifecycle hook that needs to be run.
|
||||
*
|
||||
* These two hooks are executed by the first Comp.r() instruction that runs OR the
|
||||
* first cR() instruction that runs (so inits are run for the top level view before
|
||||
* any embedded views). For this reason, the call must be tracked.
|
||||
*/
|
||||
initHooksCalled: boolean;
|
||||
|
||||
/**
|
||||
* Whether or not the afterContentInit and afterContentChecked hooks have been called
|
||||
* in this change detection run.
|
||||
* If lifecycleStage === LifecycleStage.ON_INIT, the init hooks haven't yet been run
|
||||
* and should be executed by the first r() instruction that runs OR the first
|
||||
* cR() instruction that runs (so inits are run for the top level view before any
|
||||
* embedded views).
|
||||
*
|
||||
* Content hooks are executed by the first Comp.r() instruction that runs (to avoid
|
||||
* adding to the code size), so it needs to be able to check whether or not they should
|
||||
* be called.
|
||||
* If lifecycleStage === LifecycleStage.CONTENT_INIT, the init hooks have been run, but
|
||||
* the content hooks have not yet been run. They should be executed on the first
|
||||
* r() instruction that runs.
|
||||
*
|
||||
* If lifecycleStage === LifecycleStage.VIEW_INIT, both the init hooks and content hooks
|
||||
* have already been run.
|
||||
*/
|
||||
contentHooksCalled: boolean;
|
||||
lifecycleStage: LifecycleStage;
|
||||
|
||||
/**
|
||||
* The first LView or LContainer beneath this LView in the hierarchy.
|
||||
@ -239,6 +236,18 @@ export interface TView {
|
||||
*/
|
||||
export type HookData = (number | (() => void))[];
|
||||
|
||||
/** Possible values of LView.lifecycleStage, used to determine which hooks to run. */
|
||||
export const enum LifecycleStage {
|
||||
/* Init hooks need to be run, if any. */
|
||||
INIT = 1,
|
||||
|
||||
/* Content hooks need to be run, if any. Init hooks have already run. */
|
||||
CONTENT_INIT = 2,
|
||||
|
||||
/* View hooks need to be run, if any. Any init hooks/content hooks have ran. */
|
||||
VIEW_INIT = 3
|
||||
}
|
||||
|
||||
/**
|
||||
* Static data that corresponds to the instance-specific data array on an LView.
|
||||
*
|
||||
|
Reference in New Issue
Block a user