fix(ivy): unable to inherit view queries into component from directive (#29203)
Fixes components not being able to inherit their view queries from a directive. This PR resolves FW-1146. PR Close #29203
This commit is contained in:

committed by
Matias Niemelä

parent
a5a35ff54a
commit
0ffa2f2e73
@ -129,13 +129,13 @@ export interface R3DirectiveMetadataFacade {
|
||||
usesInheritance: boolean;
|
||||
exportAs: string[]|null;
|
||||
providers: Provider[]|null;
|
||||
viewQueries: R3QueryMetadataFacade[];
|
||||
}
|
||||
|
||||
export interface R3ComponentMetadataFacade extends R3DirectiveMetadataFacade {
|
||||
template: string;
|
||||
preserveWhitespaces: boolean;
|
||||
animations: any[]|undefined;
|
||||
viewQueries: R3QueryMetadataFacade[];
|
||||
pipes: Map<string, any>;
|
||||
directives: {selector: string, expression: any}[];
|
||||
styles: string[];
|
||||
|
@ -597,6 +597,12 @@ export const defineDirective = defineComponent as any as<T>(directiveDefinition:
|
||||
*/
|
||||
contentQueries?: ContentQueriesFunction<T>;
|
||||
|
||||
/**
|
||||
* Additional set of instructions specific to view query processing. This could be seen as a
|
||||
* set of instructions to be inserted into the template function.
|
||||
*/
|
||||
viewQuery?: ViewQueriesFunction<T>| null;
|
||||
|
||||
/**
|
||||
* Defines the name that can be used in the template to assign this directive to a variable.
|
||||
*
|
||||
|
@ -73,18 +73,17 @@ export function InheritDefinitionFeature(definition: DirectiveDef<any>| Componen
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,6 +158,13 @@ export interface DirectiveDef<T> extends BaseDef<T> {
|
||||
*/
|
||||
contentQueries: ContentQueriesFunction<T>|null;
|
||||
|
||||
/**
|
||||
* Query-related instructions for a directive. Note that while directives don't have a
|
||||
* view and as such view queries won't necessarily do anything, there might be
|
||||
* components that extend the directive.
|
||||
*/
|
||||
viewQuery: ViewQueriesFunction<T>|null;
|
||||
|
||||
/**
|
||||
* Refreshes host bindings on the associated directive.
|
||||
*/
|
||||
|
@ -63,8 +63,6 @@ export function compileComponent(type: Type<any>, metadata: Component): void {
|
||||
preserveWhitespaces: metadata.preserveWhitespaces || false,
|
||||
styles: metadata.styles || EMPTY_ARRAY,
|
||||
animations: metadata.animations,
|
||||
viewQueries:
|
||||
extractQueriesMetadata(type, getReflect().ownPropMetadata(type), isViewQuery),
|
||||
directives: [],
|
||||
changeDetection: metadata.changeDetection,
|
||||
pipes: new Map(),
|
||||
@ -157,6 +155,7 @@ export function directiveMetadata(type: Type<any>, metadata: Directive): R3Direc
|
||||
usesInheritance: !extendsDirectlyFromObject(type),
|
||||
exportAs: extractExportAs(metadata.exportAs),
|
||||
providers: metadata.providers || null,
|
||||
viewQueries: extractQueriesMetadata(type, propMetadata, isViewQuery),
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user