feat(ivy): support attaching and detaching views from change detection (#22670)

PR Close #22670
This commit is contained in:
Kara Erickson
2018-03-08 16:55:47 -08:00
parent b0b9ca3386
commit b26a90567c
6 changed files with 237 additions and 29 deletions

View File

@ -210,7 +210,7 @@ export function createLView(
const newView = {
parent: currentView,
id: viewId, // -1 for component views
flags: flags | LViewFlags.CreationMode,
flags: flags | LViewFlags.CreationMode | LViewFlags.Attached,
node: null !, // until we initialize it in createNode.
data: [],
tView: tView,
@ -1281,14 +1281,19 @@ export function directiveRefresh<T>(directiveIndex: number, elementIndex: number
assertNotNull(element.data, `Component's host node should have an LView attached.`);
const hostView = element.data !;
// Only CheckAlways components or dirty OnPush components should be checked
if (hostView.flags & (LViewFlags.CheckAlways | LViewFlags.Dirty)) {
// Only attached CheckAlways components or attached, dirty OnPush components should be checked
if (viewAttached(hostView) && hostView.flags & (LViewFlags.CheckAlways | LViewFlags.Dirty)) {
ngDevMode && assertDataInRange(directiveIndex);
detectChangesInternal(hostView, element, getDirectiveInstance<T>(data[directiveIndex]));
}
}
}
/** Returns a boolean for whether the view is attached */
function viewAttached(view: LView): boolean {
return (view.flags & LViewFlags.Attached) === LViewFlags.Attached;
}
/**
* Instruction to distribute projectable nodes among <ng-content> occurrences in a given template.
* It takes all the selectors from the entire component's template and decides where