ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

Ember.Component shouldn't require a template

Open ryanflorence opened this issue 13 years ago • 13 comments

Currently you can have a template-only component, but not a class-only component.

Lots of components are simply an element and aren't intended to have anything to {{yield}}.

Ember should be happy to take a component where only the JS class is defined, ie:

App.XAwesomeButtonComponent = Ember.Component.extend();

ryanflorence avatar Aug 28 '13 15:08 ryanflorence

As I was in this code yesterday fix things, I was also thinking of this.

There are several Component related funky things, especially since they are directly integrated with template helpers

https://github.com/emberjs/ember.js/blob/master/packages/ember-handlebars/lib/loader.js#L61-L87

stefanpenner avatar Aug 28 '13 15:08 stefanpenner

Agree.

Really weird to have templates like:

<script type="text/x-handlebars" id="components/mycomp">
</script>

raulbrito avatar Aug 28 '13 15:08 raulbrito

I agree completely. My only issue would be how to infer where the dash goes (for container lookup). We could just infer after the first word and allow overriding...

rwjblue avatar Aug 28 '13 15:08 rwjblue

@rjackson maybe they require explicit templateNames set? or a helperName property?

stefanpenner avatar Aug 28 '13 15:08 stefanpenner

dashes are easy, just dasherize the title case.

FooBarBazComponent -> foo-bar-baz

A component should never be foo-barBaz, it doesn't map to web components.

ryanflorence avatar Aug 28 '13 19:08 ryanflorence

@rpflorence That makes it much easier. Was thinking we had to support the other pattern also...

rwjblue avatar Aug 28 '13 19:08 rwjblue

@rpflorence interesting..

stefanpenner avatar Aug 28 '13 19:08 stefanpenner

Components that are defined in JS and registered with .helper no longer get an implicit template.

wycats avatar Aug 31 '13 02:08 wycats

For anyone stumbling along later: http://emberjs.com/api/classes/Ember.Handlebars.html#method_helper

trek avatar Aug 31 '13 11:08 trek

So, is it possible to have a Component that doesn't have a template? If so then how? If not, then I think that it should be supported. I've just raised a discussion about component templates on discuss.emberjs.com if anyone's interested.

simonexmachina avatar Oct 29 '13 09:10 simonexmachina

@aexmachina - It is definitely possible. You need to register the handlebars helper manually.

Ember.Handlebars.helper('my-component-name', App.MyComponentName);

Example here.

rwjblue avatar Oct 29 '13 15:10 rwjblue

@rwjblue Your example no longer works in 1.8. Is this still possible? Thanks

pwfisher avatar Sep 19 '14 03:09 pwfisher

@rwjblue we used that trick on 1.6, now we are starting a new project with 2.2 and that function doesn't exists anymore. Is there a working solution for 2.2?

ZaHgO avatar Nov 30 '15 17:11 ZaHgO