The original post was asking how to dynamically load template-only components. My reply was that there’s nothing special about template-only components when it comes to how you’d load them. Under embroider, you can dynamically load any component. And since the above was written, we released ember-auto-import 2.0 which lets you dynamically import components out of v2 addons even without switching your app to embroider.
Your question is about how much can be done with template-only components.
Firstly, there’s no pressure to use template-only components. They’re appropriate sometimes but not all times, and JS-backed Glimmer components are a first-class part of Octane-edition Ember.
Second, I think we should be precise about what we mean by template-only. One meaning is “a component with no javascript” and another is “a component with no backing class”. Traditionally in ember those collapsed into one concept, because if you want to have any Javascript you need to create a backing class. But that is not true for proposed formats like GJS, where you can make locally-scoped helpers, modifiers, and components and then invoke them from the template, all without ever making a class extends Component {}
.
As an illustrative example, imagine you want to both offer a default fill
and assert that any developer-provided fill satisfies a11y contrast requirements within your design system. I can see doing that with a template-only component like this:
import { fillFor } from '@bigco/theme-system';
<template>
<svg fill={{fillFor "icon" @fill}}>Your Icon Here</svg>
</template>
I’m using the proposed GJS format as implemented in GitHub - ember-template-imports/ember-template-imports: Template import support in Ember!.
The use of the ES import makes it clearer where your theme rules are coming from. fillFor
would be implemented as a helper. And even though this is a “template-only component”, if you needed a little Javascript to glue things together or adjust them, you could have some, even though your component is still just a template with no JS class:
import Theme from '@bigco/theme-system';
function fillFor(userFill) {
return Theme.find("new-mobile").fillFor("icon", userFill);
}
<template>
<svg fill={{ (fillFor @fill) }}>Your Icon Here</svg>
</template>
In this second example, I’m assuming Default Helper Manager by NullVoxPopuli · Pull Request #756 · emberjs/rfcs · GitHub which eliminates the need to wrap our funciton fillFor
in Ember’s helper()
utility.