Skip to content

Get {{component}} working more robustly #20

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

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

dfreeman
Copy link
Member

@dfreeman dfreeman commented Sep 7, 2020

This change very nearly gets the types for {{component}} working correctly.

For components with no type parameters, everything should work as expected. Any number of named args may be pre-bound, and they become optional when invoking the resulting component value.

For components with type parameters, if arguments not involved with the type parameters (or none at all) are pre-bound, any type params on the constructor are preserved in the resulting component value.

In other words, {{component AnimatedEach use=this.transition}} will result in a value with a signature like <T>(args: { items: Array<T> }) => AcceptsBlocks<{ default: [T, number] }>, so the type of items passed in will be reflected in the yielded block parameter.

The one place that requires care is if you wish to pre-bind an arg that fixes a type parameter on the component in question. To accomplish that, the type parameter itself needs to be fixed outside of template space, i.e.

const StringAnimatedEach = AnimatedEach as new () => AnimatedEach<string>;

hbs`
  {{yield (component StringAnimatedEach items=(array 1 2 3))}}
`;

This also ignores positional parameters, but to be honest I'm not actually 100% sure what the semantics for partial application are there anyway, and they're not supported by Glimmer components or by angle bracket invocation, so that feels like an ok loss.

@dfreeman dfreeman added the enhancement New feature or request label Sep 7, 2020
@dfreeman dfreeman merged commit c5b3092 into master Sep 7, 2020
@dfreeman dfreeman deleted the more-robust-component-keyword branch September 7, 2020 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant