Skip to content

Commit 2767f07

Browse files
committed
Switch method to check for equality
1 parent 0da832e commit 2767f07

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/plot_api/helpers.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var isNumeric = require('fast-isnumeric');
4-
var m4FromQuat = require('gl-mat4/fromQuat');
54

65
var Registry = require('../registry');
76
var Lib = require('../lib');
@@ -510,39 +509,40 @@ exports.clearAxisTypes = function (gd, traces, layoutUpdate) {
510509
};
511510

512511
/**
513-
* Check if a collection (object or array) has changed given two versions of
514-
* the collection: old and new.
512+
* Check if two collections (object or array) are equal
515513
*
516-
* @param {Object|Array} oldCollection: Old version of collection to compare
517-
* @param {Object|Array} newCollection: New version of collection to compare
514+
* @param {Object|Array} collection1: First collection to compare
515+
* @param {Object|Array} collection2: Second collection to compare
518516
*/
519-
const hasCollectionChanged = (oldCollection, newCollection) => {
517+
const collectionsAreEqual = (collection1, collection2) => {
520518
const isArrayOrObject = (...vals) => vals.every((v) => Lib.isPlainObject(v)) || vals.every((v) => Array.isArray(v));
521-
if ([oldCollection, newCollection].every((a) => Array.isArray(a))) {
522-
if (oldCollection.length !== newCollection.length) return true;
519+
if ([collection1, collection2].every((a) => Array.isArray(a))) {
520+
if (collection1.length !== collection2.length) return false;
523521

524-
for (let i = 0; i < oldCollection.length; i++) {
525-
const oldVal = oldCollection[i];
526-
const newVal = newCollection[i];
522+
for (let i = 0; i < collection1.length; i++) {
523+
const oldVal = collection1[i];
524+
const newVal = collection2[i];
527525
if (oldVal !== newVal) {
528-
const hasChanged = isArrayOrObject(oldVal, newVal) ? hasCollectionChanged(oldVal, newVal) : true;
529-
if (hasChanged) return true;
526+
const equal = isArrayOrObject(oldVal, newVal) ? collectionsAreEqual(oldVal, newVal) : false;
527+
if (!equal) return false;
530528
}
531529
}
530+
531+
return true;
532532
} else {
533-
if (Object.keys(oldCollection).length !== Object.keys(newCollection).length) return true;
533+
if (Object.keys(collection1).length !== Object.keys(collection2).length) return false;
534534

535-
for (const k in oldCollection) {
535+
for (const k in collection1) {
536536
if (k.startsWith('_')) continue;
537-
const oldVal = oldCollection[k];
538-
const newVal = newCollection[k];
537+
const oldVal = collection1[k];
538+
const newVal = collection2[k];
539539
if (oldVal !== newVal) {
540-
const hasChanged = isArrayOrObject(oldVal, newVal) ? hasCollectionChanged(oldVal, newVal) : true;
541-
if (hasChanged) return true;
540+
const equal = isArrayOrObject(oldVal, newVal) ? collectionsAreEqual(oldVal, newVal) : false;
541+
if (!equal) return false;
542542
}
543543
}
544-
}
545544

546-
return false;
545+
return true;
546+
}
547547
};
548-
exports.hasCollectionChanged = hasCollectionChanged;
548+
exports.collectionsAreEqual = collectionsAreEqual;

src/plot_api/plot_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ function react(gd, data, layout, config) {
26102610
const oldConfig = Lib.extendDeepAll({}, gd._context);
26112611
gd._context = undefined;
26122612
setPlotContext(gd, config);
2613-
configChanged = helpers.hasCollectionChanged(oldConfig, gd._context);
2613+
configChanged = !helpers.collectionsAreEqual(oldConfig, gd._context);
26142614
}
26152615

26162616
if (configChanged) {

0 commit comments

Comments
 (0)