Skip to content

Commit

Permalink
Event listeners of update now receive an extra property data, con…
Browse files Browse the repository at this point in the history
…taining the changed fields of the changed items.
  • Loading branch information
josdejong committed Sep 18, 2014
1 parent 107c49a commit 1ffaba5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 11 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions docs/dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,10 @@ <h3 id="Callback">Callback</h3>
In case of the events <code>add</code>,
<code>update</code>, and <code>remove</code>,
<code>properties</code> is always an object containing a property
items, which contains an array with the ids of the affected
items.
<code>items</code>, which contains an array with the ids of the affected
items. The <code>update</code> event has an extra field <code>data</code>
containing the original data of the updated items, i.e. the gives the
changed fields of the changed items.
</td>
</tr>
<tr>
Expand Down
12 changes: 7 additions & 5 deletions lib/DataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,19 @@ 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];
if (me._data[id]) {
// update item
id = me._updateItem(item);
updatedIds.push(id);
updatedData.push(item);
}
else {
// add new item
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1ffaba5

Please sign in to comment.