From 1eccf093ac110813948e1f21fcad98dfe6eaf480 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sat, 7 Nov 2015 22:08:00 +0100 Subject: [PATCH 1/2] cloning old data before updating to fix #1378 --- lib/DataSet.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/DataSet.js b/lib/DataSet.js index b87ddcd7..1ffadc93 100644 --- a/lib/DataSet.js +++ b/lib/DataSet.js @@ -243,10 +243,11 @@ DataSet.prototype.update = function (data, senderId) { var addOrUpdate = function (item) { var id = item[fieldId]; if (me._data[id]) { + var oldData = util.extend({}, me._data[id]); // update item id = me._updateItem(item); updatedIds.push(id); - updatedData.push(item); + updatedData.push(oldData); } else { // add new item @@ -513,7 +514,7 @@ DataSet.prototype.forEach = function (callback, options) { var filter = options && options.filter, type = options && options.type || this._options.type, data = this._data, - itemIds = Object.key(data), + itemIds = Object.keys(data), i, len, item, From a09df56a45df8e9f4e2e1ca9dafa82ba23d82f0b Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 10 Nov 2015 20:10:12 +0100 Subject: [PATCH 2/2] defined a read only property 'data' to avoid breaking the api --- lib/DataSet.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/DataSet.js b/lib/DataSet.js index 1ffadc93..25ede879 100644 --- a/lib/DataSet.js +++ b/lib/DataSet.js @@ -274,7 +274,15 @@ DataSet.prototype.update = function (data, senderId) { this._trigger('add', {items: addedIds}, senderId); } if (updatedIds.length) { - this._trigger('update', {items: updatedIds, data: updatedData}, senderId); + var props = { items: updatedIds, oldData: updatedData }; + // TODO: remove deprecated property 'data' some day + Object.defineProperty(props, 'data', { + 'get': (function() { + console.warn('Property data is deprecated. Use DataSet.get(ids) to retrieve the new data, use the oldData property on this object to get the old data'); + return this.get(updatedIds); + }).bind(this) + }); + this._trigger('update', props, senderId); } return addedIds.concat(updatedIds);