-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App.container was not meant to be a public API
It appears that people are starting to use App.container.lookup as the public API for globally getting other controllers outside of the router or other controllers. This was not intended to be a public API. Instead, you should trigger events on a route (or a parent route), which have access to `this.controllerFor`. Example: App.ApplicationRoute.extend({ events: { search: function(term) { this.controllerFor('search') .set('term', term); } } }); App.SearchField = Ember.TextField.extend({ insertNewline: function() { var term = this.get('value'), controller = this.get('controller'); controller.send('search', term); this.set('value', ''); } }); Events sent to the controller will bubble up to the current route, and then up the route hierarchy
- Loading branch information
Showing
2 changed files
with
18 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every time we catch someone recommending calling
App.__container__.lookup
in IRC, we will add another pair of underscores.5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomdale sgb
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hilarious
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example doesnt seem to work - see fiddle http://jsfiddle.net/6NyfN/
Context inside event is the handler itself, not the controller so no controllerFor.
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My vote is still for
App.__c_o_n_t_a_i_n_e_r__
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomdale if there are so many uses of this internal API it means that people don't understand how to tie all the pieces together.
I am confused myself with many aspects, for example, property bindings between controllers, real use cases of view objects which looks like we can handle without them, refresh model data from server and more.
It could be great to have a tutorial for building a real app (not just a basic one as @trek is building, which is very helpful also).
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 @ramigg
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want this to be painful so that you guys report use cases that are not easily resolved using other methods!
We now provide the
needs
property onEmber.Controller
, which allows you to explicitly declare your dependencies and then have them available on your controllers. Please see 8f60000 for more.5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not using ember data and I use simple Ember.Object for my models. I want to lookup my custom store and adapter inside my model, how do I do that? The only way I see this working is through the container.lookup('adapter:xxxx')
Basically, I have a cascadding dropdown situation and I want to load the children when the parent is set on the model. in order to do that I need access to the store and/or adapter. Any ideas? Or am I going about this the wrong way?
5becdc4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eibrahim this is better asked on StackOverflow or on Discourse.
You can inject your store into all/specific controllers/routes so it's available from there - you certainly shouldn't need to use the container directly as it's a private implementation detail and it's interface is not guaranteed to stay stable.
Eg I do this with my custom data store in an initializer: https://github.com/rlivsey/fireplace/blob/master/app/initializers/store.js
Coming soon this will be able to be done with services which is currently behind a feature flag on canary.
If you want to go into this some more then please open up a thread on StackOverflow or Discourse as they are much better venues for discussion.