feat(ivy): support OnPush change detection (#22417)

PR Close #22417
This commit is contained in:
Kara Erickson
2018-02-23 13:17:20 -08:00
committed by Alex Eagle
parent e454c5a98e
commit 8c358844dd
11 changed files with 470 additions and 110 deletions

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ChangeDetectionStrategy} from '../../change_detection/constants';
import {PipeTransform} from '../../change_detection/pipe_transform';
import {RendererType2} from '../../render/api';
import {Type} from '../../type';
@ -124,6 +125,9 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
* NOTE: only used with component directives.
*/
readonly rendererType: RendererType2|null;
/** Whether or not this component's ChangeDetectionStrategy is OnPush */
readonly onPush: boolean;
}
/**
@ -169,6 +173,7 @@ export interface ComponentDefArgs<T> extends DirectiveDefArgs<T> {
template: ComponentTemplate<T>;
features?: ComponentDefFeature[];
rendererType?: RendererType2;
changeDetection?: ChangeDetectionStrategy;
}
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;

View File

@ -24,16 +24,7 @@ import {Renderer3} from './renderer';
* don't have to edit the data array based on which views are present.
*/
export interface LView {
/**
* Flags for this view.
*
* First bit: Whether or not the view is in creationMode.
*
* This must be stored in the view rather than using `data` as a marker so that
* we can properly support embedded views. Otherwise, when exiting a child view
* back into the parent view, `data` will be defined and `creationMode` will be
* improperly reported as false.
*/
/** Flags for this view (see LViewFlags for definition of each bit). */
flags: LViewFlags;
/**
@ -182,9 +173,23 @@ export interface LView {
queries: LQueries|null;
}
/** Flags associated with an LView (see LView.flags) */
export enum LViewFlags {
CreationMode = 0b001
/** Flags associated with an LView (saved in LView.flags) */
export const enum LViewFlags {
/**
* Whether or not the view is in creationMode.
*
* This must be stored in the view rather than using `data` as a marker so that
* we can properly support embedded views. Otherwise, when exiting a child view
* back into the parent view, `data` will be defined and `creationMode` will be
* improperly reported as false.
*/
CreationMode = 0b001,
/** Whether this view has default change detection strategy (checks always) or onPush */
CheckAlways = 0b010,
/** Whether or not this view is currently dirty (needing check) */
Dirty = 0b100
}
/** Interface necessary to work with view tree traversal */