Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support empty object context #768

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions projects/ng-polymorpheus/src/directives/outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export class PolymorpheusOutlet<C> implements OnChanges, DoCheck {
private c?: ComponentRef<unknown>;

@Input('polymorpheusOutlet')
public content: PolymorpheusContent<C> = '';
public content: PolymorpheusContent<C | Record<never, never>> = '';

@Input('polymorpheusOutletContext')
public context?: C;
public context?: C | Record<never, never>;

public static ngTemplateContextGuard<T>(
_dir: PolymorpheusOutlet<T>,
Expand All @@ -55,7 +55,9 @@ export class PolymorpheusOutlet<C> implements OnChanges, DoCheck {
context &&
(new Proxy(context as object, {
get: (_, key) =>
this.getContext()?.[key as keyof (C | PolymorpheusContext<any>)],
this.getContext()?.[
key as keyof (C | PolymorpheusContext<any> | Record<never, never>)
],
}) as unknown as C);

if (isComponent(this.content)) {
Expand All @@ -81,7 +83,11 @@ export class PolymorpheusOutlet<C> implements OnChanges, DoCheck {
return this.content instanceof TemplateRef ? this.content : this.t;
}

private getContext(): C | PolymorpheusContext<any> | undefined {
private getContext():
| C
| PolymorpheusContext<any>
| Record<never, never>
| undefined {
if (isTemplate(this.content) || isComponent(this.content)) {
return this.context;
}
Expand Down
Loading