|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | var isNumeric = require('fast-isnumeric'); |
4 | | -var m4FromQuat = require('gl-mat4/fromQuat'); |
5 | 4 |
|
6 | 5 | var Registry = require('../registry'); |
7 | 6 | var Lib = require('../lib'); |
@@ -510,39 +509,40 @@ exports.clearAxisTypes = function (gd, traces, layoutUpdate) { |
510 | 509 | }; |
511 | 510 |
|
512 | 511 | /** |
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 |
515 | 513 | * |
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 |
518 | 516 | */ |
519 | | -const hasCollectionChanged = (oldCollection, newCollection) => { |
| 517 | +const collectionsAreEqual = (collection1, collection2) => { |
520 | 518 | 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; |
523 | 521 |
|
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]; |
527 | 525 | 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; |
530 | 528 | } |
531 | 529 | } |
| 530 | + |
| 531 | + return true; |
532 | 532 | } 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; |
534 | 534 |
|
535 | | - for (const k in oldCollection) { |
| 535 | + for (const k in collection1) { |
536 | 536 | if (k.startsWith('_')) continue; |
537 | | - const oldVal = oldCollection[k]; |
538 | | - const newVal = newCollection[k]; |
| 537 | + const oldVal = collection1[k]; |
| 538 | + const newVal = collection2[k]; |
539 | 539 | 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; |
542 | 542 | } |
543 | 543 | } |
544 | | - } |
545 | 544 |
|
546 | | - return false; |
| 545 | + return true; |
| 546 | + } |
547 | 547 | }; |
548 | | -exports.hasCollectionChanged = hasCollectionChanged; |
| 548 | +exports.collectionsAreEqual = collectionsAreEqual; |
0 commit comments