Skip to content

Commit db28bad

Browse files
crisbetothePunderWoman
authored andcommitted
feat(core): enable the new directive composition API (#47642)
Enables the new directive composition API by exposing the `hostDirectives` property on the `Directive` and `Component` decorators. Also cleans up some casts that were put in place while the feature was being developed. Fixes #8785. PR Close #47642
1 parent 7702a3d commit db28bad

4 files changed

Lines changed: 118 additions & 121 deletions

File tree

‎goldens/public-api/core/index.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ export interface Directive {
439439
host?: {
440440
[key: string]: string;
441441
};
442+
hostDirectives?: (Type<unknown> | {
443+
directive: Type<unknown>;
444+
inputs?: string[];
445+
outputs?: string[];
446+
})[];
442447
inputs?: string[];
443448
jit?: true;
444449
outputs?: string[];

‎packages/core/src/metadata/directives.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ export interface Directive {
332332
* @developerPreview
333333
*/
334334
standalone?: boolean;
335+
336+
/**
337+
* Standalone directives that should be applied to the host whenever the directive is matched.
338+
* By default none of the inputs or outputs of the host directives will be available on the host,
339+
* unless they are specified in the `inputs` or `outputs` properties.
340+
*/
341+
hostDirectives?: (Type<unknown>|{
342+
directive: Type<unknown>,
343+
inputs?: string[],
344+
outputs?: string[],
345+
})[];
335346
}
336347

337348
/**

‎packages/core/src/render3/jit/directive.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,8 @@ export function directiveMetadata(type: Type<any>, metadata: Directive): R3Direc
416416
providers: metadata.providers || null,
417417
viewQueries: extractQueriesMetadata(type, propMetadata, isViewQuery),
418418
isStandalone: !!metadata.standalone,
419-
hostDirectives:
420-
// TODO(crisbeto): remove the `as any` usage here and down in the `map` call once
421-
// host directives are exposed in the public API.
422-
(metadata as any)
423-
.hostDirectives?.map(
424-
(directive: any) => typeof directive === 'function' ? {directive} : directive) ||
419+
hostDirectives: metadata.hostDirectives?.map(
420+
directive => typeof directive === 'function' ? {directive} : directive) ||
425421
null
426422
};
427423
}

0 commit comments

Comments
 (0)