Browse Source

Merge pull request #1423 from hansmaulwurf23/issue_1378

cloning old data before updating to fix #1378
fixDataView
Jos de Jong 8 years ago
parent
commit
9a200c6ee8
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      lib/DataSet.js

+ 12
- 3
lib/DataSet.js View File

@ -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
@ -273,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);
@ -513,7 +522,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,

Loading…
Cancel
Save