Browse Source

Fixed the DataView not passing a data property on update events (see #670)

v3_develop
jos 9 years ago
parent
commit
876d233b53
3 changed files with 57 additions and 9 deletions
  1. +3
    -1
      HISTORY.md
  2. +9
    -7
      lib/DataView.js
  3. +45
    -1
      test/DataView.test.js

+ 3
- 1
HISTORY.md View File

@ -14,7 +14,9 @@ http://visjs.org
- Added pull request for usage of Icons. Thanks @Dude9177!
- Allow hierarchical view to be set in setOptions.
- Fixed manipulation bar for mobile.
- Fixed #670: bug when updating data in a DataSet, when Network is connected to the DataSet via a DataView.
- Fixed #670:
- Bug when updating data in a DataSet, when Network is connected to the DataSet via a DataView.
- Fixed the DataView not passing a data property on update events (see #670)
### Graph2d

+ 9
- 7
lib/DataView.js View File

@ -258,12 +258,13 @@ DataView.prototype.getDataSet = function () {
* @private
*/
DataView.prototype._onEvent = function (event, params, senderId) {
var i, len, id, item,
ids = params && params.items,
data = this._data,
added = [],
updated = [],
removed = [];
var i, len, id, item;
var ids = params && params.items;
var data = this._data;
var updatedData = [];
var added = [];
var updated = [];
var removed = [];
if (ids && data) {
switch (event) {
@ -290,6 +291,7 @@ DataView.prototype._onEvent = function (event, params, senderId) {
if (item) {
if (this._ids[id]) {
updated.push(id);
updatedData.push(params.data[i]);
}
else {
this._ids[id] = true;
@ -328,7 +330,7 @@ DataView.prototype._onEvent = function (event, params, senderId) {
this._trigger('add', {items: added}, senderId);
}
if (updated.length) {
this._trigger('update', {items: updated}, senderId);
this._trigger('update', {items: updated, data: updatedData}, senderId);
}
if (removed.length) {
this._trigger('remove', {items: removed}, senderId);

+ 45
- 1
test/DataView.test.js View File

@ -146,5 +146,49 @@ describe('DataView', function () {
assert.deepEqual(added, [2, 3]);
assert.deepEqual(updated, []);
assert.deepEqual(removed, []);
})
});
it('should pass data of changed items when updating a DataSet', function () {
var data = new DataSet([
{id: 1, title: 'Item 1', group: 1},
{id: 2, title: 'Item 2', group: 2},
{id: 3, title: 'Item 3', group: 2}
]);
var view = new DataView(data, {
filter: function (item) {
return item.group === 2;
}
});
var dataUpdates = [];
var viewUpdates = [];
data.on('update', function (event, properties, senderId) {
dataUpdates.push([event, properties]);
});
view.on('update', function (event, properties, senderId) {
viewUpdates.push([event, properties]);
});
// make a change not affecting the DataView
data.update({id: 1, title: 'Item 1 (changed)'});
assert.deepEqual(dataUpdates, [
['update', {items: [1], data: [{id: 1, title: 'Item 1 (changed)'}]}]
]);
assert.deepEqual(viewUpdates, []);
// make a change affecting the DataView
data.update({id: 2, title: 'Item 2 (changed)'});
assert.deepEqual(dataUpdates, [
['update', {items: [1], data: [{id: 1, title: 'Item 1 (changed)'}]}],
['update', {items: [2], data: [{id: 2, title: 'Item 2 (changed)'}]}]
]);
assert.deepEqual(viewUpdates, [
['update', {items: [2], data: [{id: 2, title: 'Item 2 (changed)'}]}]
]);
});
});

Loading…
Cancel
Save