Here is a stripped down example of a component which waits for some async stuff:
{{x-foo onSearch='findThings'}}
If the component happens to be destroyed, the promise which is searching for new results will still callback to the component, but the component will be dead by that time.
Perhaps this:
{{x-foo results=results}}
would solve the problem? But it is less nice.
Wrap your results object into some sort of model called result-set for instance. On result-set would be a search function which takes a query and updates it’s isSaving isError values like ember data does, it also has a content value which contains the actual results. The component would sendAction(‘search’, query) and the router would call search on the result-set the data would go down to the components via data bindings for isError, isSaving, and content. The component template would reference isError, isSaving, and content to display the different states.
…fine, except that dropdown box is nested 2 levels deep. So 9 things have to be passed down through the layers which results in a lot of confusing code.
You can bundle them together IE filesError and files and filesSaving would all be in the file object which you pass down. Then you can unbundle as you go to remove the need for name spacing things like errors.
{{#if model.isSaving}}
{{else if model.isError}}
{{else}}
{{! loop through the model.content or whatever you want to call the actual results}}
{{/if}}
If it’s even deeper you can again bundle according to whatever makes sense for you. I used an architecture sort of like this in one of my ember apps and it turned out to be useful for error and saving handling since each component knew if it was saving/erring no matter where the save was called since the model held that data not the controller.
The thing I didn’t like and don’t yet have a good solution for is getting the actions to the top to be handled but I’ve been playing with the idea of using services to short circuit events to the top since the service is a singleton and I can use it to manage all data interactions. Not sure if it’s a good idea yet…
To me it’s because that’s the architecture that ember seems to be supporting.
Ignoring the details of implementation I think the difference can be boiled down to observer style MVC vs controller heavy MVC. ie observer style the view observes the model and updates itself, controller heavy the controller serves as an intermediary for view model interactions.
I’ve tried both approaches across a few different languages (actionscript, C#, java). They both have advantages and disadvantages and ultimately I did end up liking the more controller heavy approach better.
BUT
In learning ember I’ve felt that the expectation of the architecture is to follow a more observer based approach. I’ve also gotten a similar sense from poking around discuss and other ember environments. In a very opinionated framework such as ember I’ve found it advantageous to adapt to the architecture rather than impose my personal preference.