Permalink
Browse files

Refactor LayoutView to use _removeChild

  • Loading branch information...
Ryan Eastridge
Ryan Eastridge committed Dec 27, 2012
1 parent c8632c7 commit c47336bab8a1c70438a1683bd493df812c76c25a
Showing with 16 additions and 9 deletions.
  1. +16 −9 src/layout.js
View
@@ -75,20 +75,27 @@ Thorax.LayoutView = Thorax.View.extend({
if (options.destroy && view) {
view._shouldDestroyOnNextSetView = true;
}
+
this.trigger('change:view:start', view, oldView, options);
- oldView && oldView.trigger('deactivated', options);
- view && view.trigger('activated', options);
- if (oldView && oldView.el && oldView.el.parentNode) {
+
+ if (oldView) {
+ this._removeChild(oldView);
oldView.$el.remove();
+ oldView.trigger('deactivated', options);
+ if (oldView._shouldDestroyOnNextSetView) {
+ oldView.destroy();
+ }
}
- //make sure the view has been rendered at least once
- view && this._addChild(view);
- this._view = view || undefined;
- oldView && (delete this.children[oldView.cid]);
- oldView && oldView._shouldDestroyOnNextSetView && oldView.destroy();
- if (this._view) {
+
+ if (view) {
+ view.trigger('activated', options);
+ this._addChild(view);
+ this._view = view;
this._view.appendTo(getLayoutViewsTargetElement.call(this));
+ } else {
+ this._view = undefined;
}
+
this.trigger('change:view:end', view, oldView, options);
return view;
},

0 comments on commit c47336b

Please sign in to comment.