@@ -585,45 +585,46 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou
585
585
} ;
586
586
587
587
/**
588
- * Relink private _keys and keys with a function value from one layout
589
- * (usually cached) to the new fullLayout .
590
- * relink means copying if object is pass-by-value and adding a reference
591
- * if object is pass-by-ref. This prevents deepCopying massive structures like
592
- * a webgl context.
588
+ * Relink private _keys and keys with a function value from one container
589
+ * to the new container .
590
+ * Relink means copying if object is pass-by-value and adding a reference
591
+ * if object is pass-by-ref.
592
+ * This prevents deepCopying massive structures like a webgl context.
593
593
*/
594
- function relinkPrivateKeys ( toLayout , fromLayout ) {
595
- var keys = Object . keys ( fromLayout ) ;
596
- var j ;
594
+ function relinkPrivateKeys ( toContainer , fromContainer ) {
595
+ var isPlainObject = Lib . isPlainObject ,
596
+ isArray = Array . isArray ;
597
+
598
+ var keys = Object . keys ( fromContainer ) ;
599
+
600
+ for ( var i = 0 ; i < keys . length ; i ++ ) {
601
+ var k = keys [ i ] ,
602
+ fromVal = fromContainer [ k ] ,
603
+ toVal = toContainer [ k ] ;
604
+
605
+ if ( k . charAt ( 0 ) === '_' || typeof fromVal === 'function' ) {
597
606
598
- for ( var i = 0 ; i < keys . length ; ++ i ) {
599
- var k = keys [ i ] ;
600
- if ( k . charAt ( 0 ) === '_' || typeof fromLayout [ k ] === 'function' ) {
601
607
// if it already exists at this point, it's something
602
608
// that we recreate each time around, so ignore it
603
- if ( k in toLayout ) continue ;
609
+ if ( k in toContainer ) continue ;
604
610
605
- toLayout [ k ] = fromLayout [ k ] ;
611
+ toContainer [ k ] = fromVal ;
606
612
}
607
- else if ( Array . isArray ( fromLayout [ k ] ) &&
608
- Array . isArray ( toLayout [ k ] ) &&
609
- fromLayout [ k ] . length &&
610
- Lib . isPlainObject ( fromLayout [ k ] [ 0 ] ) ) {
611
- if ( fromLayout [ k ] . length !== toLayout [ k ] . length ) {
612
- // this should be handled elsewhere, it causes
613
- // ambiguity if we try to deal with it here.
614
- throw new Error ( 'relinkPrivateKeys needs equal ' +
615
- 'length arrays' ) ;
616
- }
613
+ else if ( isArray ( fromVal ) && isArray ( toVal ) ) {
617
614
618
- for ( j = 0 ; j < fromLayout [ k ] . length ; j ++ ) {
619
- relinkPrivateKeys ( toLayout [ k ] [ j ] , fromLayout [ k ] [ j ] ) ;
615
+ // recurse into arrays
616
+ for ( var j = 0 ; j < fromVal . length ; j ++ ) {
617
+ if ( isPlainObject ( fromVal [ j ] ) && isPlainObject ( toVal [ j ] ) ) {
618
+ relinkPrivateKeys ( toVal [ j ] , fromVal [ j ] ) ;
619
+ }
620
620
}
621
621
}
622
- else if ( Lib . isPlainObject ( fromLayout [ k ] ) &&
623
- Lib . isPlainObject ( toLayout [ k ] ) ) {
622
+ else if ( isPlainObject ( fromVal ) && isPlainObject ( toVal ) ) {
623
+
624
624
// recurse into objects, but only if they still exist
625
- relinkPrivateKeys ( toLayout [ k ] , fromLayout [ k ] ) ;
626
- if ( ! Object . keys ( toLayout [ k ] ) . length ) delete toLayout [ k ] ;
625
+ relinkPrivateKeys ( toVal , fromVal ) ;
626
+
627
+ if ( ! Object . keys ( toVal ) . length ) delete toContainer [ k ] ;
627
628
}
628
629
}
629
630
}
0 commit comments