refactor(ivy): add type and hooks to directive def (#21650)

PR Close #21650
This commit is contained in:
Kara Erickson
2018-01-22 15:27:21 -08:00
committed by Misko Hevery
parent 97b928053d
commit 98174758ad
20 changed files with 196 additions and 77 deletions

View File

@ -27,6 +27,9 @@ export const enum DirectiveDefFlags {ContentQuery = 0b10}
* `DirectiveDef` is a compiled version of the Directive used by the renderer instructions.
*/
export interface DirectiveDef<T> {
/** Token representing the directive. Used by DI. */
type: Type<T>;
/** Function that makes a directive public to the DI system. */
diPublic: ((def: DirectiveDef<any>) => void)|null;
@ -85,6 +88,9 @@ export interface DirectiveDef<T> {
// (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;
}
export interface ComponentDef<T> extends DirectiveDef<T> {
@ -122,17 +128,19 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
readonly rendererType: RendererType2|null;
}
/**
* Private: do not export
*/
export interface TypedDirectiveDef<T> extends DirectiveDef<T> { type: DirectiveType<T>; }
/**
* Private: do not export
*/
export interface TypedComponentDef<T> extends ComponentDef<T> { type: ComponentType<T>; }
/* 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;
refresh?: (directiveIndex: number, elementIndex: number) => void;
inputs?: {[P in keyof T]?: string};