Browse Source

Graph3d put guards before unsubscription in DataGroup (#3271)

**Note:** This is a small fix and should be easy to review.

Second fix for #3251.

In method `DataGroup.initializeData()`, if the passed `rawData` is bad for some reason,
it was possible to lose the subscriptions due to early return from the method.

This fix changes the order in the method so that the guard clauses execute *before* the
subscription is changed.
revert-3409-performance
wimrijnders 7 years ago
committed by yotamberk
parent
commit
0fa017f59f
1 changed files with 7 additions and 9 deletions
  1. +7
    -9
      lib/graph3d/DataGroup.js

+ 7
- 9
lib/graph3d/DataGroup.js View File

@ -35,13 +35,7 @@ function DataGroup() {
* @param {Number} style Style Number * @param {Number} style Style Number
*/ */
DataGroup.prototype.initializeData = function(graph3d, rawData, style) { DataGroup.prototype.initializeData = function(graph3d, rawData, style) {
// unsubscribe from the dataTable
if (this.dataSet) {
this.dataSet.off('*', this._onChange);
}
if (rawData === undefined)
return;
if (rawData === undefined) return;
if (Array.isArray(rawData)) { if (Array.isArray(rawData)) {
rawData = new DataSet(rawData); rawData = new DataSet(rawData);
@ -55,8 +49,12 @@ DataGroup.prototype.initializeData = function(graph3d, rawData, style) {
throw new Error('Array, DataSet, or DataView expected'); throw new Error('Array, DataSet, or DataView expected');
} }
if (data.length == 0)
return;
if (data.length == 0) return;
// unsubscribe from the dataTable
if (this.dataSet) {
this.dataSet.off('*', this._onChange);
}
this.dataSet = rawData; this.dataSet = rawData;
this.dataTable = data; this.dataTable = data;

Loading…
Cancel
Save