fix(ivy): support queries for views inserted in lifecycle hooks (#24587)

Closes #23707

PR Close #24587
This commit is contained in:
Pawel Kozlowski
2018-06-19 17:58:42 +02:00
committed by Miško Hevery
parent 1e6a226703
commit 3e1a3b2e32
13 changed files with 1243 additions and 862 deletions

View File

@ -8,7 +8,6 @@
import {SimpleChange} from '../change_detection/change_detection_util';
import {ChangeDetectionStrategy} from '../change_detection/constants';
import {PipeTransform} from '../change_detection/pipe_transform';
import {Provider} from '../core';
import {OnChanges, SimpleChanges} from '../metadata/lifecycle_hooks';
import {NgModuleDef, NgModuleDefInternal} from '../metadata/ng_module';
@ -17,7 +16,7 @@ import {Type} from '../type';
import {resolveRendererType2} from '../view/util';
import {diPublic} from './di';
import {ComponentDefFeature, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {ComponentDefFeature, ComponentDefInternal, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {CssSelectorList, SelectorFlags} from './interfaces/projection';
@ -126,6 +125,16 @@ export function defineComponent<T>(componentDefinition: {
*/
template: ComponentTemplate<T>;
/**
* Additional set of instructions specific to view query processing. This could be seen as a
* set of instruction to be inserted into the template function.
*
* Query-related instructions need to be pulled out to a specific function as a timing of
* execution is different as compared to all other instructions (after change detection hooks but
* before view hooks).
*/
viewQuery?: ComponentQuery<T>| null;
/**
* A list of optional features to apply.
*
@ -193,7 +202,8 @@ export function defineComponent<T>(componentDefinition: {
pipeDefs: pipeTypes ?
() => (typeof pipeTypes === 'function' ? pipeTypes() : pipeTypes).map(extractPipeDef) :
null,
selectors: componentDefinition.selectors
selectors: componentDefinition.selectors,
viewQuery: componentDefinition.viewQuery || null,
};
const feature = componentDefinition.features;
feature && feature.forEach((fn) => fn(def));