I have a Container view that I am using as my main wrapper view, in which other views are swapped in and out.
In Ember 0.9.8 this worked fine. However, now in Ember 1.0pre I get an error when I try to swap in a view that I had previously swapped out.
Here’s my basic code:
App.globalView = Ember.ContainerView.create({
screenOne: App.screenOne.create(),
screenTwo: App.screenTwo.create()
});
App.globalView.set('currentView', App.globalView.get('screenOne')); // <-- good
App.globalView.set('currentView', App.globalView.get('screenTwo')); // <-- good
App.globalView.set('currentView', App.globalView.get('screenOne')); // <-- BAD
I now get the error
Error: assertion failed: calling set on destroyed object
...from
Ember.ContainerView.Ember.View.extend.initializeViews
set(view, '_parentView', parentView);
I have an example of this at http://jsfiddle.net/SamFent/WmfTX/. In the jsFiddle, I don’t see the error but the previous view just fails to load.
Does anyone know what’s going on?
Ember.ContainerView now destroys the view when it is unset, so it cannot be used as you want. Here is a fork of your fiddle that does what you want: http://jsfiddle.net/WmfTX/1/
If you really need to avoid tearing down and recreating views, render both views and use the
isVisibleproperty to toggle visibility instead.