Describe the glimmer-factory better including the motive

This commit is contained in:
Michael Lange 2020-10-15 10:35:23 -07:00
parent 41df088abe
commit 56bf526778
1 changed files with 15 additions and 8 deletions

View File

@ -1,11 +1,8 @@
// Look up the component class in the glimmer component manager and return a
// function to construct components as if they were functions.
const glimmerComponentInstantiator = (owner, componentKey) => args => {
const componentManager = owner.lookup('component-manager:glimmer');
const componentClass = owner.factoryFor(`component:${componentKey}`).class;
return componentManager.createComponent(componentClass, { named: args });
};
// Used in glimmer component unit tests. Glimmer components should typically
// be tested with integration tests, but occasionally individual methods or
// properties have logic that isn't coupled to rendering or the DOM and can
// be better tested in a unit fashion.
//
// Use like
//
// setupGlimmerComponentFactory(hooks, 'my-component')
@ -23,3 +20,13 @@ export default function setupGlimmerComponentFactory(hooks, componentKey) {
delete this.createComponent;
});
}
// Look up the component class in the glimmer component manager and return a
// function to construct components as if they were functions.
function glimmerComponentInstantiator(owner, componentKey) {
return args => {
const componentManager = owner.lookup('component-manager:glimmer');
const componentClass = owner.factoryFor(`component:${componentKey}`).class;
return componentManager.createComponent(componentClass, { named: args });
};
}