This document aims to help aggregate issues and solutions around the defaultContainer deprecation.
The Error Message:
Using the defaultContainer is no longer supported. [defaultContainer#lookup]
Well it is still there, and will continue to work for some time. Likely it will be gone by 1.0.0 final
We recieved several issues, these issues were non-obvious but it appeared that they where caused by the defaultContainer leaking between tests. This obviously lead to very unexpected test failures. The quick fix was obviously to ensure the defaultContainer was purged between tests. Upon further investigation, almost all the issues turned out to be childViews which were not wired up correctly. For example not using this.createChildView
on creation of childViews. Ultimately, the existence of the defaultContainer was masking the reported issues, and likely many more. In addition the obvious issues, we are trying to remove our dependency on globals (but that is another story).
if you are creating dynamic views in the context of the parentView, you should be using:
this.createChildView(viewClass, viewAttributes)
if you are creating views outside the context of a parentView (this may not be recommended, but it is happening) you will want to make sure to instantiate your view via the container itself.
this.container.lookup('view:apple')
// will provide a instance of apple view.
how container lookups are resolved
- appendTo another ember view, should then grab the container of that view.
- continue to flush out this gist
- improve docs/guides
- improve deprecation warnings
- explore methods where this works without developer thought (without perf regressions)
Post a comment, describing the issue, and hopefully a jsbin or jsfiddle demonstrating the issue. As time permits, a solution or migration path will finds its way up into this document.
A: App is the root, and as such it creates the initial container.
A: typically, it is using the container passed down the view hierarchy, and this typically occurs at creation.
A: likely, but its not just the container, it is a place for the framework to wire-up other things. https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/view.js#L2072
(ask questions in the comments and I will hoist them here.)
So... I have an interesting scenario that I don't see brought up here yet (either that or I'm just not understanding something).
I've been in the process of creating a rather large CRUD application with 14 data types to manage (more will be coming later); so as I've been creating this application, I've been developing a "component" library that is capable of auto-generating Twitter Bootstrap forms from JSON.
For one of my newest form components, the user can see a list of items, edit them, remove them, or add to them. When adding or editing, a generated Modal Form pops up to capture the user's input with the Modal's own Form Element.
So... the Ember View that creates the list and "Add" button are all inside of the "main" Form; meanwhile the Modal needs to be added to the DOM so that it can expose it's own Form.
I only just got that bit working today... before, I just didn't have the Modal expose a Form, and it was just embedded in the parent view. But then there were interesting side-effects when property names collide and just the general lack of HTML5 Form Validation.
Here is how my "ItemList" component is currently managing the ModalForm. (Note: It's pretty rough at the moment since I'm really just trying to get things to work)
So, if there's a much better way to do something like this, please let me know. If not, I'd prefer to be able to append Views to the DOM when needed. It isn't often.