Browse Source

Fixed #1437: Restored `data` property of the update event of DataSet.

fixDataView
jos 8 years ago
parent
commit
5f0755a373
3 changed files with 284 additions and 66 deletions
  1. +2
    -3
      docs/data/dataset.html
  2. +12
    -10
      lib/DataSet.js
  3. +270
    -53
      test/networkTest.html

+ 2
- 3
docs/data/dataset.html View File

@ -599,9 +599,8 @@ function (event, properties, senderId) {
<code>properties</code> is always an object containing a property
<code>items</code>, which contains an array with the ids of the affected
items. The <code>update</code> event has an extra field <code>oldData</code>
containing the original data of the updated items, which allows to
determine the changed fields of the changed items when comparing to
the new item properties.
containing the original data of the updated items, and a field <code>data</code>
containing the changes: the properties of the items that are being updated.
</td>
</tr>
<tr>

+ 12
- 10
lib/DataSet.js View File

@ -236,6 +236,7 @@ DataSet.prototype.add = function (data, senderId) {
DataSet.prototype.update = function (data, senderId) {
var addedIds = [];
var updatedIds = [];
var oldData = [];
var updatedData = [];
var me = this;
var fieldId = me._fieldId;
@ -243,11 +244,12 @@ 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]);
var oldItem = util.extend({}, me._data[id]);
// update item
id = me._updateItem(item);
updatedIds.push(id);
updatedData.push(oldData);
updatedData.push(item);
oldData.push(oldItem);
}
else {
// add new item
@ -274,14 +276,14 @@ DataSet.prototype.update = function (data, senderId) {
this._trigger('add', {items: addedIds}, senderId);
}
if (updatedIds.length) {
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)
});
var props = { items: updatedIds, oldData: oldData, data: 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 updatedData;
// }).bind(this)
//});
this._trigger('update', props, senderId);
}

+ 270
- 53
test/networkTest.html
File diff suppressed because it is too large
View File


Loading…
Cancel
Save