-
-
Notifications
You must be signed in to change notification settings - Fork 405
Description
... for creation and rendering of such templates.
This is provoked from this Discord discussion.
The main point is as follows. I have the following code currently (Ember 3.15):
import Component from '@ember/component';
import { createTemplateFactory } from '@ember/template-factory';
...
const component = Component.extend({ tagName: '', layout: createTemplateFactory(precompiledTemplate) });
getOwner(this).lookup('application:main').register(componentName, component);
...
const component = getOwner(this).factoryFor(componentName).create();
component.on('didRender', function() {
const html = this.element.innerHTML;
...
});
component.appendTo('...');It dynamically creates a classic component, registers it, instantiates it and the instance is rendered on the page to extract some info from it.
In order to achieve the same result with a Glimmer component, the first part of the code could be translated like so:
import { setComponentTemplate } from '@ember/component';
import { createTemplateFactory } from '@ember/template-factory';
import GlimmerComponent from '@glimmer/component';
const CustomComponent = class extends GlimmerComponent {};
setComponentTemplate(createTemplateFactory(precompiledTemplate), CustomComponent);
getOwner(this).lookup('application:main').register(componentName, CustomComponent);However the other parts have no Glimmer counterparts. I would have expected at least getOwner(this).factoryFor(componentName).create() to work fine but it blows up with Failed to create an instance of 'component:some-component'. Most likely an improperly defined class or an invalid module export..
Having a unified JavaScript API for component creation and rendering for any kind of component (classic, Glimmer, template-only Glimmer) would be nice. Not sure if it makes sense or is something Ember wants to invest in, but I just wanted to put this here so a discussion can be started.
CC @Gaurav0