feat(ivy): add query inheritance (#25556)
Adds inheritance handling for the following: - viewQuery - contentQueries - contentQueriesRefresh PR Close #25556
This commit is contained in:
@ -8,7 +8,8 @@
|
||||
|
||||
import {Type} from '../../type';
|
||||
import {fillProperties} from '../../util/property';
|
||||
import {ComponentDefInternal, DirectiveDefFeature, DirectiveDefInternal} from '../interfaces/definition';
|
||||
import {ComponentDefInternal, ComponentTemplate, DirectiveDefFeature, DirectiveDefInternal, RenderFlags} from '../interfaces/definition';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -68,6 +69,51 @@ export function InheritDefinitionFeature(
|
||||
}
|
||||
}
|
||||
|
||||
// Merge View Queries
|
||||
if (isComponentDef(definition) && isComponentDef(superDef)) {
|
||||
const prevViewQuery = definition.viewQuery;
|
||||
const superViewQuery = superDef.viewQuery;
|
||||
if (superViewQuery) {
|
||||
if (prevViewQuery) {
|
||||
definition.viewQuery = <T>(rf: RenderFlags, ctx: T): void => {
|
||||
superViewQuery(rf, ctx);
|
||||
prevViewQuery(rf, ctx);
|
||||
};
|
||||
} else {
|
||||
definition.viewQuery = superViewQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge Content Queries
|
||||
const prevContentQueries = definition.contentQueries;
|
||||
const superContentQueries = superDef.contentQueries;
|
||||
if (superContentQueries) {
|
||||
if (prevContentQueries) {
|
||||
definition.contentQueries = () => {
|
||||
superContentQueries();
|
||||
prevContentQueries();
|
||||
};
|
||||
} else {
|
||||
definition.contentQueries = superContentQueries;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge Content Queries Refresh
|
||||
const prevContentQueriesRefresh = definition.contentQueriesRefresh;
|
||||
const superContentQueriesRefresh = superDef.contentQueriesRefresh;
|
||||
if (superContentQueriesRefresh) {
|
||||
if (prevContentQueriesRefresh) {
|
||||
definition.contentQueriesRefresh = (directiveIndex: number, queryIndex: number) => {
|
||||
superContentQueriesRefresh(directiveIndex, queryIndex);
|
||||
prevContentQueriesRefresh(directiveIndex, queryIndex);
|
||||
};
|
||||
} else {
|
||||
definition.contentQueriesRefresh = superContentQueriesRefresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Merge inputs and outputs
|
||||
fillProperties(definition.inputs, superDef.inputs);
|
||||
fillProperties(definition.declaredInputs, superDef.declaredInputs);
|
||||
|
@ -221,7 +221,7 @@ export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T
|
||||
/**
|
||||
* Query-related instructions for a component.
|
||||
*/
|
||||
readonly viewQuery: ComponentQuery<T>|null;
|
||||
viewQuery: ComponentQuery<T>|null;
|
||||
|
||||
/**
|
||||
* The view encapsulation type, which determines how styles are applied to
|
||||
|
Reference in New Issue
Block a user