-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
support invoking components with render
#1181
support invoking components with render
#1181
Conversation
addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Outdated
Show resolved
Hide resolved
b1f100f
to
baee787
Compare
options?: RenderOptions | ||
): Promise<void> { | ||
let context = getContext(); | ||
let template: TemplateFactory; | ||
|
||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk if there is a better way to check this
baee787
to
7707804
Compare
@NullVoxPopuli could we add support for arguments? await render(SomeComponent, { key: 'value' }); or it should be an side thing? context.setProperties({ __renderable__: renderable, args, attrs });
const argsForComponent = Object.keys(args).reduce((acc, key) => {
return `${acc} @${key}={{this.args.${key}}}`;
}, '');
const attrsForComponent = Object.keys(attrs).reduce((acc, key) => {
return `${acc} ${key}={{this.attrs.${key}}}`;
}, '');
template = hbs`<this.__renderable__ ${argsForComponent} ${attrsForComponent}/>`; to support reactive mutations on args, https://github.com/lifeart/glimmerx-workshop/blob/master/src/test-helpers/index.ts#L7 may be used. example: https://github.com/lifeart/glimmerx-workshop/blob/master/src/components/Icon.spec.ts#L12 |
I think if you want to pass args, you'd do: let fromTestScope = 2;
await render(
<template>
<MyComponent @arg={{2}} @foo={{fromTestScope}} />
</template)
)
That does look like a handy shorthand. |
Just checking (without looking 😂) – does this align with the direction suggested by/straight-up implement emberjs/rfcs#785? Such that you could now just pass it |
This work is a little unrelated to RFC#785, but maybe implemented support by accident? as is, I've been testing with |
This is the same as what is being proposed in emberjs/rfcs#785 (that just adds a way to create a component without also requiring folks use |
We need to move that RFC forward before proceeding here. |
alright 🤷 class Toggle extends Component {
// ... no args
}
setComponentTemplate(hbs`...`, Toggle);
await render(Toggle); 🥳 |
addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Outdated
Show resolved
Hide resolved
addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Outdated
Show resolved
Hide resolved
addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Outdated
Show resolved
Hide resolved
} else { | ||
template = renderable as TemplateFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make passing a component work when we aren't under 3.25 as well, the same basic way that ensureSafeComponent
works. Something like this:
let randomComponentName = `render-test-helper-${uuid++}`;
owner.register(`component:${randomComponentName}`, renderable);
this.set('__renderable__', randomComponentName);
template = hbs`{{component this.__renderable__}}`;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want or need to though?
The capability requested here landed in 2.8.0+ 🎉 |
adds support for
or
This usage only makes sense if the component takes no args.
alternatively, we could make ember-template-imports not turn the
<template>
into a component withinrender
, but I feel like that could get complicated when people define the<template>
outside of render and then try to pass it render, and then we're back at the same problem.