Skip to content

Commit

Permalink
feat(core): enable the new directive composition API (#47642)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
crisbeto authored and thePunderWoman committed Oct 6, 2022
1 parent 7702a3d commit db28bad
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 121 deletions.
5 changes: 5 additions & 0 deletions goldens/public-api/core/index.md
Expand Up @@ -439,6 +439,11 @@ export interface Directive {
host?: {
[key: string]: string;
};
hostDirectives?: (Type<unknown> | {
directive: Type<unknown>;
inputs?: string[];
outputs?: string[];
})[];
inputs?: string[];
jit?: true;
outputs?: string[];
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/metadata/directives.ts
Expand Up @@ -332,6 +332,17 @@ export interface Directive {
* @developerPreview
*/
standalone?: boolean;

/**
* Standalone directives that should be applied to the host whenever the directive is matched.
* By default none of the inputs or outputs of the host directives will be available on the host,
* unless they are specified in the `inputs` or `outputs` properties.
*/
hostDirectives?: (Type<unknown>|{
directive: Type<unknown>,
inputs?: string[],
outputs?: string[],
})[];
}

/**
Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/render3/jit/directive.ts
Expand Up @@ -416,12 +416,8 @@ export function directiveMetadata(type: Type<any>, metadata: Directive): R3Direc
providers: metadata.providers || null,
viewQueries: extractQueriesMetadata(type, propMetadata, isViewQuery),
isStandalone: !!metadata.standalone,
hostDirectives:
// TODO(crisbeto): remove the `as any` usage here and down in the `map` call once
// host directives are exposed in the public API.
(metadata as any)
.hostDirectives?.map(
(directive: any) => typeof directive === 'function' ? {directive} : directive) ||
hostDirectives: metadata.hostDirectives?.map(
directive => typeof directive === 'function' ? {directive} : directive) ||
null
};
}
Expand Down

0 comments on commit db28bad

Please sign in to comment.