From eb0777e04d2a69f43d5c833a6641ffa981c8be7d Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 27 Mar 2017 21:32:24 +0800 Subject: [PATCH] add --- bi/core.js | 25 ++++++++++++++++++------- dist/core.js | 25 ++++++++++++++++++------- src/core/mvc/fbi.js | 8 ++++---- src/core/view.js | 17 ++++++++++++++--- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/bi/core.js b/bi/core.js index ae283440f..55eea25e4 100644 --- a/bi/core.js +++ b/bi/core.js @@ -1131,7 +1131,7 @@ BI.Factory = { _init: function(){}, //容器,默认放在this.element上 - _vessel: function(){return this.element}, + _vessel: function(){return this}, // **render** is the core function that your view should override, in order // to populate its element (`this.el`), with the appropriate HTML. The // convention is for **render** to always return `this`. @@ -1230,21 +1230,21 @@ BI.Factory = { // using `selector`). This only works for delegate-able events: not `focus`, // `blur`, and not `change`, `submit`, and `reset` in Internet Explorer. delegate: function(eventName, selector, listener) { - this.$vessel.on(eventName + '.delegateEvents' + this.cid, selector, listener); + this.$vessel.element.on(eventName + '.delegateEvents' + this.cid, selector, listener); }, // Clears all callbacks previously bound to the view by `delegateEvents`. // You usually don't need to use this, but may wish to if you have multiple // BI views attached to the same DOM element. undelegateEvents: function() { - if (this.$vessel) this.$vessel.off('.delegateEvents' + this.cid); + if (this.$vessel) this.$vessel.element.off('.delegateEvents' + this.cid); return this; }, // A finer-grained `undelegateEvents` for removing a single delegated event. // `selector` and `listener` are both optional. undelegate: function(eventName, selector, listener) { - this.$vessel.off(eventName + '.delegateEvents' + this.cid, selector, listener); + this.$vessel.element.off(eventName + '.delegateEvents' + this.cid, selector, listener); }, // Produces a DOM element to be assigned to your view. Exposed for @@ -5370,7 +5370,7 @@ BI.View = BI.inherit(BI.V, { }); var vessel = BI.createWidget(); this._cardLayouts[this.getName()].addCardByName(this.getName(), vessel); - return vessel.element; + return vessel; }, _render: function (vessel) { @@ -5741,15 +5741,26 @@ BI.View = BI.inherit(BI.V, { }, + _unMount: function () { + BI.each(this._cardLayouts, function (name, card) { + card && card._unMount(); + }); + delete this._cardLayouts; + delete this._cards; + this.off(); + this.destroyed(); + }, + destroy: function () { BI.each(this._cardLayouts, function (name, card) { - card && card.destroy(); + card && card._unMount(); }); delete this._cardLayouts; delete this._cards; + this.destroyed(); this.remove(); this.trigger(BI.Events.DESTROY); - this.destroyed(); + this.off(); }, destroyed: function () { diff --git a/dist/core.js b/dist/core.js index ceb4a35c6..19d0eea11 100644 --- a/dist/core.js +++ b/dist/core.js @@ -12147,7 +12147,7 @@ BI.Factory = { _init: function(){}, //容器,默认放在this.element上 - _vessel: function(){return this.element}, + _vessel: function(){return this}, // **render** is the core function that your view should override, in order // to populate its element (`this.el`), with the appropriate HTML. The // convention is for **render** to always return `this`. @@ -12246,21 +12246,21 @@ BI.Factory = { // using `selector`). This only works for delegate-able events: not `focus`, // `blur`, and not `change`, `submit`, and `reset` in Internet Explorer. delegate: function(eventName, selector, listener) { - this.$vessel.on(eventName + '.delegateEvents' + this.cid, selector, listener); + this.$vessel.element.on(eventName + '.delegateEvents' + this.cid, selector, listener); }, // Clears all callbacks previously bound to the view by `delegateEvents`. // You usually don't need to use this, but may wish to if you have multiple // BI views attached to the same DOM element. undelegateEvents: function() { - if (this.$vessel) this.$vessel.off('.delegateEvents' + this.cid); + if (this.$vessel) this.$vessel.element.off('.delegateEvents' + this.cid); return this; }, // A finer-grained `undelegateEvents` for removing a single delegated event. // `selector` and `listener` are both optional. undelegate: function(eventName, selector, listener) { - this.$vessel.off(eventName + '.delegateEvents' + this.cid, selector, listener); + this.$vessel.element.off(eventName + '.delegateEvents' + this.cid, selector, listener); }, // Produces a DOM element to be assigned to your view. Exposed for @@ -15291,7 +15291,7 @@ BI.View = BI.inherit(BI.V, { }); var vessel = BI.createWidget(); this._cardLayouts[this.getName()].addCardByName(this.getName(), vessel); - return vessel.element; + return vessel; }, _render: function (vessel) { @@ -15662,15 +15662,26 @@ BI.View = BI.inherit(BI.V, { }, + _unMount: function () { + BI.each(this._cardLayouts, function (name, card) { + card && card._unMount(); + }); + delete this._cardLayouts; + delete this._cards; + this.off(); + this.destroyed(); + }, + destroy: function () { BI.each(this._cardLayouts, function (name, card) { - card && card.destroy(); + card && card._unMount(); }); delete this._cardLayouts; delete this._cards; + this.destroyed(); this.remove(); this.trigger(BI.Events.DESTROY); - this.destroyed(); + this.off(); }, destroyed: function () { diff --git a/src/core/mvc/fbi.js b/src/core/mvc/fbi.js index 9a70f5c49..135de6363 100644 --- a/src/core/mvc/fbi.js +++ b/src/core/mvc/fbi.js @@ -1080,7 +1080,7 @@ _init: function(){}, //容器,默认放在this.element上 - _vessel: function(){return this.element}, + _vessel: function(){return this}, // **render** is the core function that your view should override, in order // to populate its element (`this.el`), with the appropriate HTML. The // convention is for **render** to always return `this`. @@ -1179,21 +1179,21 @@ // using `selector`). This only works for delegate-able events: not `focus`, // `blur`, and not `change`, `submit`, and `reset` in Internet Explorer. delegate: function(eventName, selector, listener) { - this.$vessel.on(eventName + '.delegateEvents' + this.cid, selector, listener); + this.$vessel.element.on(eventName + '.delegateEvents' + this.cid, selector, listener); }, // Clears all callbacks previously bound to the view by `delegateEvents`. // You usually don't need to use this, but may wish to if you have multiple // BI views attached to the same DOM element. undelegateEvents: function() { - if (this.$vessel) this.$vessel.off('.delegateEvents' + this.cid); + if (this.$vessel) this.$vessel.element.off('.delegateEvents' + this.cid); return this; }, // A finer-grained `undelegateEvents` for removing a single delegated event. // `selector` and `listener` are both optional. undelegate: function(eventName, selector, listener) { - this.$vessel.off(eventName + '.delegateEvents' + this.cid, selector, listener); + this.$vessel.element.off(eventName + '.delegateEvents' + this.cid, selector, listener); }, // Produces a DOM element to be assigned to your view. Exposed for diff --git a/src/core/view.js b/src/core/view.js index b5e19022d..02a250bf3 100644 --- a/src/core/view.js +++ b/src/core/view.js @@ -130,7 +130,7 @@ BI.View = BI.inherit(BI.V, { }); var vessel = BI.createWidget(); this._cardLayouts[this.getName()].addCardByName(this.getName(), vessel); - return vessel.element; + return vessel; }, _render: function (vessel) { @@ -501,15 +501,26 @@ BI.View = BI.inherit(BI.V, { }, + _unMount: function () { + BI.each(this._cardLayouts, function (name, card) { + card && card._unMount(); + }); + delete this._cardLayouts; + delete this._cards; + this.off(); + this.destroyed(); + }, + destroy: function () { BI.each(this._cardLayouts, function (name, card) { - card && card.destroy(); + card && card._unMount(); }); delete this._cardLayouts; delete this._cards; + this.destroyed(); this.remove(); this.trigger(BI.Events.DESTROY); - this.destroyed(); + this.off(); }, destroyed: function () {