Browse Source

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

fixDataView
jos 9 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>properties</code> is always an object containing a property
<code>items</code>, which contains an array with the ids of the affected <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> 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> </td>
</tr> </tr>
<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) { DataSet.prototype.update = function (data, senderId) {
var addedIds = []; var addedIds = [];
var updatedIds = []; var updatedIds = [];
var oldData = [];
var updatedData = []; var updatedData = [];
var me = this; var me = this;
var fieldId = me._fieldId; var fieldId = me._fieldId;
@ -243,11 +244,12 @@ DataSet.prototype.update = function (data, senderId) {
var addOrUpdate = function (item) { var addOrUpdate = function (item) {
var id = item[fieldId]; var id = item[fieldId];
if (me._data[id]) { if (me._data[id]) {
var oldData = util.extend({}, me._data[id]);
var oldItem = util.extend({}, me._data[id]);
// update item // update item
id = me._updateItem(item); id = me._updateItem(item);
updatedIds.push(id); updatedIds.push(id);
updatedData.push(oldData);
updatedData.push(item);
oldData.push(oldItem);
} }
else { else {
// add new item // add new item
@ -274,14 +276,14 @@ DataSet.prototype.update = function (data, senderId) {
this._trigger('add', {items: addedIds}, senderId); this._trigger('add', {items: addedIds}, senderId);
} }
if (updatedIds.length) { 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); this._trigger('update', props, senderId);
} }

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


Loading…
Cancel
Save