Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js converting controller / view architecture to components

I have an existing DetailController and DetailView in my app that has some pretty complicated UI / data manipulation logic (hotkeys, copy paste, duplication, autocomplete, etc) -- the view sends UI events to the controller; the controller handles the logic.

I want to convert this to an Ember component.

  1. Does this basically mean I merge the view and controller into DetailComponent? This seems messy and wrong to me.
  2. If not, how do I use controllers and views internally within a component? That is, I still want the complete isolation and well-defined public interface of the component, but internally within the component, I'd like to use controllers and views for organization. Is that possible?
  3. Is it possible to use {{render}}, {{view}}, {{partial}} within the component template?
like image 232
Sherwin Yu Avatar asked Oct 22 '22 02:10

Sherwin Yu


1 Answers

Does this basically mean I merge the view and controller into DetailComponent? This seems messy and wrong to me.

Yes that is what it means.

internally within the component, I'd like to use controllers and views for organization. Is that possible?

So component basically replaces a single view/controller pair. Beyond that a component is just an extension of Ember.View and can be organized just like any other view.

Is it possible to use {{render}}, {{view}}, {{partial}} within the component template?

Yes. Any of those helpers will work.

like image 75
Mike Grassotti Avatar answered Oct 25 '22 19:10

Mike Grassotti