Skip to content

Instantly share code, notes, and snippets.

@lifeart
Last active March 12, 2021 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeart/a6478a5e1965575115b900813ffd4d8d to your computer and use it in GitHub Desktop.
Save lifeart/a6478a5e1965575115b900813ffd4d8d to your computer and use it in GitHub Desktop.
ember template imports
import Component from "@glimmer/component";
import { helper } from "@ember/component/helper";
import { setComponentTemplate } from "@ember/component";
import { hbs as tpl } from "ember-cli-htmlbars";
function asHelper(a, b, c) {
return {
value: helper(function (positional) {
return c.value.call(a, ...positional);
})
};
}
function asComponent(a, b, c) {
class MyComponent extends Component {}
return {
value: setComponentTemplate(c.initializer(), MyComponent)
};
}
export default class ExampleComponent extends Component {
@asHelper
myFn(a) {
return a || 42;
}
@asComponent
myComponent = tpl`<h1>Hello</h1>`;
}
{{this.myFn "23"}}
<this.myComponent />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment