From 1ffaba543c8a9e05b5e6845de1bdff2e64f0e272 Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 18 Sep 2014 10:53:35 +0200 Subject: [PATCH] Event listeners of `update` now receive an extra property `data`, containing the changed fields of the changed items. --- HISTORY.md | 14 +++++++++++--- docs/dataset.html | 6 ++++-- lib/DataSet.js | 12 +++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a8d1a024..1ecee113 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,7 +2,15 @@ http://visjs.org -## 2014-10-16, version 3.5.0 +## not yet released, version 3.5.1 + +### DataSet + +- Event listeners of `update` now receive an extra property `data`, + containing the changed fields of the changed items. + + +## 2014-09-16, version 3.5.0 ### Network @@ -15,7 +23,7 @@ http://visjs.org - Fixed dataAxis not showing large numbers correctly. -## 2014-10-12, version 3.4.2 +## 2014-09-12, version 3.4.2 ### Network @@ -25,7 +33,7 @@ http://visjs.org - Fixed minor bug in positioning of fontFill of nodes with certain shapes. -## 2014-10-11, version 3.4.1 +## 2014-09-11, version 3.4.1 ### Network diff --git a/docs/dataset.html b/docs/dataset.html index 57010e1d..17d2ab13 100644 --- a/docs/dataset.html +++ b/docs/dataset.html @@ -448,8 +448,10 @@ function (event, properties, senderId) { In case of the events add, update, and remove, properties is always an object containing a property - items, which contains an array with the ids of the affected - items. + items, which contains an array with the ids of the affected + items. The update event has an extra field data + containing the original data of the updated items, i.e. the gives the + changed fields of the changed items. diff --git a/lib/DataSet.js b/lib/DataSet.js index d22a5c04..d0565848 100644 --- a/lib/DataSet.js +++ b/lib/DataSet.js @@ -204,10 +204,11 @@ DataSet.prototype.add = function (data, senderId) { * @return {Array} updatedIds The ids of the added or updated items */ DataSet.prototype.update = function (data, senderId) { - var addedIds = [], - updatedIds = [], - me = this, - fieldId = me._fieldId; + var addedIds = []; + var updatedIds = []; + var updatedData = []; + var me = this; + var fieldId = me._fieldId; var addOrUpdate = function (item) { var id = item[fieldId]; @@ -215,6 +216,7 @@ DataSet.prototype.update = function (data, senderId) { // update item id = me._updateItem(item); updatedIds.push(id); + updatedData.push(item); } else { // add new item @@ -254,7 +256,7 @@ DataSet.prototype.update = function (data, senderId) { this._trigger('add', {items: addedIds}, senderId); } if (updatedIds.length) { - this._trigger('update', {items: updatedIds}, senderId); + this._trigger('update', {items: updatedIds, data: updatedData}, senderId); } return addedIds.concat(updatedIds);