I'm working on refactoring an inherited Ember application, with quite a bit of non-mvc disorder to it. I'm looking to keep things as modular as possible, and am hoping to reuse various ui components in multiple screens to help prevent code duplication.
It seems like outlets are the best way to do this.
Right now, I have a UI displaying a number of elements, each rendered using a templatized view.
{{#each item in controller}}
{{view App.ItemThumbView}}
{{/each}}
The right sidebar of this view is an outlet that changes based on the selection. When I select an item, I would like to display a list of edit operations within the templatized sub-view, which when selected, reveal the proper edit UI through a nested outlet.
Essentially
+---------------------------------------------------+
| Parent Pane
|
| +------------------------------+ +----------+
| | Device Section | | Sidebar |
| | | | [Outlet] |
| | +--------+ +---------+ | | |
| | | Dev 1 | | Dev 2 | | | |
| | |[outlet]| | [outlet]| | +----------+
| | +--------+ +---------+ |
| +------------------------------+
+--------------------------------------------------+
The nested views all share the same controller -- which makes sense -- but I need to be able to connect a selected view to its corresponding outlet. My initial attempts at connecting outlets never display. The code doesn't fail at all, so the controller's just updating a hidden outlet.
How do I target the correct outlet for a nested view in Ember? (At best, I seem to be able to hit the sidebar outlet, but not the outlet within a nested device template.) And is this a reasonable structure for implementing contextual menus in ember in the first place?
* For clarification With my current setup, each device item is rendered using the same template. When selected, the sidebar outlet would update with some device's meta information, while the selected device view would also connect its outlet to an edit menu. Only one device item would have its 'edit' outlet connected at a time.
Does it make sense to even use an outlet here, or should I be dropping conditional logic into the template in order to display the edit menus as necessary?
Update to restate the best practices portion of the question:
Outlets seem to be great for decoupling components, and future-proofing potential view nestings. But right now it seems like accessing the correct outlet for a nested view is a bit cumbersome. Further, if you always know what component(s) will be conditionally nested within a template, it seems easiestto just hardcode your views. eg:
// within template used for individual result-list items
{{#if condition }}
{{view reusableSubView}}
{{/if}
What is the preferred ember way of doing things here? Is there any overhead to creating outlets that may not necessarily be connected at all times?