From 86f10a15ab864068637c123eaf7ec0cbf57c144c Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 8 Aug 2017 14:38:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/core.js | 36 +++++++++++++++++++++++++++++++++++- docs/core.js | 36 +++++++++++++++++++++++++++++++++++- src/core/model.js | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/bi/core.js b/bi/core.js index b50973e43..219e5e21e 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4904,7 +4904,41 @@ BI.Widget = BI.inherit(BI.OB, { }, _change: function (child) { - this.set(this._map(child)); + var self = this; + var childMap = this._map(child); + //this.set(childMap); + var changes = []; + var changing = this._changing; + var changed; + var options = {}; + this._changing = true; + if (!changing) { + this._previousAttributes = _.clone(this.attributes); + this.changed = {}; + } + var current = this.attributes, prev = this._previousAttributes, val; + for (var attr in childMap) { + val = childMap[attr]; + changes.push(attr); + this.changed[attr] = val; + current[attr] = val; + } + if (changes.length) this._pending = options; + for (var i = 0, length = changes.length; i < length; i++) { + this.trigger('change:' + changes[i], this, current[changes[i]], options); + } + if (changing) return this; + changed = BI.clone(this.changed); + while (this._pending) { + options = this._pending; + this._pending = false; + this.trigger('change', changed, prev, this, options); + } + this._pending = false; + this._changing = false; + if (changes.length) { + this.trigger("changed", changed, prev, this, options); + } return this; }, diff --git a/docs/core.js b/docs/core.js index 1a49400a5..1c727cb83 100644 --- a/docs/core.js +++ b/docs/core.js @@ -14900,7 +14900,41 @@ BI.Widget = BI.inherit(BI.OB, { }, _change: function (child) { - this.set(this._map(child)); + var self = this; + var childMap = this._map(child); + //this.set(childMap); + var changes = []; + var changing = this._changing; + var changed; + var options = {}; + this._changing = true; + if (!changing) { + this._previousAttributes = _.clone(this.attributes); + this.changed = {}; + } + var current = this.attributes, prev = this._previousAttributes, val; + for (var attr in childMap) { + val = childMap[attr]; + changes.push(attr); + this.changed[attr] = val; + current[attr] = val; + } + if (changes.length) this._pending = options; + for (var i = 0, length = changes.length; i < length; i++) { + this.trigger('change:' + changes[i], this, current[changes[i]], options); + } + if (changing) return this; + changed = BI.clone(this.changed); + while (this._pending) { + options = this._pending; + this._pending = false; + this.trigger('change', changed, prev, this, options); + } + this._pending = false; + this._changing = false; + if (changes.length) { + this.trigger("changed", changed, prev, this, options); + } return this; }, diff --git a/src/core/model.js b/src/core/model.js index fa7b2613b..f050d0d36 100644 --- a/src/core/model.js +++ b/src/core/model.js @@ -117,7 +117,41 @@ BI.Model = BI.inherit(BI.M, { }, _change: function (child) { - this.set(this._map(child)); + var self = this; + var childMap = this._map(child); + //this.set(childMap); + var changes = []; + var changing = this._changing; + var changed; + var options = {}; + this._changing = true; + if (!changing) { + this._previousAttributes = _.clone(this.attributes); + this.changed = {}; + } + var current = this.attributes, prev = this._previousAttributes, val; + for (var attr in childMap) { + val = childMap[attr]; + changes.push(attr); + this.changed[attr] = val; + current[attr] = val; + } + if (changes.length) this._pending = options; + for (var i = 0, length = changes.length; i < length; i++) { + this.trigger('change:' + changes[i], this, current[changes[i]], options); + } + if (changing) return this; + changed = BI.clone(this.changed); + while (this._pending) { + options = this._pending; + this._pending = false; + this.trigger('change', changed, prev, this, options); + } + this._pending = false; + this._changing = false; + if (changes.length) { + this.trigger("changed", changed, prev, this, options); + } return this; },