Glint
Search…
Template Registry
Because Ember's template resolution occurs dynamically at runtime today, Glint needs a way of mapping the names used in your templates to the actual backing value they'll be resolved to. This takes the form of a "type registry" similar to the one that powers Ember Data's types.
The recommended approach is to include a declaration in each component, modifier or helper module that adds it to the registry, which is the default export of @glint/environment-ember-loose/registry.
With first-class component templates, the day is coming when we won't need this anymore, because any components/helpers/modifiers you use will already be statically in scope, but for now this approach ensures compatibility with the effective global scope of loose-mode templates.

Components

app/components/greeting.ts
1
import Component from '@glimmer/component';
2
3
export default class Greeting extends Component {
4
// ...
5
}
6
7
declare module '@glint/environment-ember-loose/registry' {
8
export default interface Registry {
9
Greeting: typeof Greeting;
10
}
11
}
Copied!
If you've nested your component inside folder(s), you'll need to add the full "strong" name of the component to the registry. And, if you're expecting to invoke your component with curlies or the {{component}} helper, you'll need to add the component to the registry twice—once using the :: delimiter syntax and once using the / delimiter syntax. For example:
app/components/grouping/my-component.ts
1
export default class MyComponent extends Component {}
2
export default interface Registry {
3
'Grouping::MyComponent': typeof MyComponent;
4
'grouping/my-component': typeof MyComponent;
5
}
Copied!
This would let Glint understand the component if it's invoked in any of the following ways:
1
<Grouping::MyComponent />
2
3
{{grouping/my-component}}
4
5
{{#let (component 'grouping/my-component') as |Foo|}}
6
<Foo />
7
{{/let}}
Copied!

Helpers and Modifiers

Helpers and modifiers can be added to the registry using the typeof type operator in much the same way as components:
1
import { helper } from '@ember/component/helper';
2
3
const sum = helper((values: Array<number>) => {
4
return values.reduce((sum, next) => sum + next, 0);
5
});
6
7
export default sum;
8
9
declare module '@glint/environment-ember-loose/registry' {
10
export default interface Registry {
11
sum: typeof sum;
12
}
13
}
Copied!
Copy link
Edit on GitHub