@@ -67,53 +67,30 @@ exports.createCommandObserver = function(gd, container, commandList, onchange) {
6767 // Determine whether there's anything to do for this binding:
6868
6969 if ( binding ) {
70+ // Build the cache:
7071 bindingValueHasChanged ( gd , binding , ret . cache ) ;
7172
7273 ret . check = function check ( ) {
7374 if ( ! enabled ) return ;
7475
75- var container , value , obj ;
76- var changed = false ;
76+ var update = bindingValueHasChanged ( gd , binding , ret . cache ) ;
7777
78- if ( binding . type === 'data' ) {
79- // If it's data, we need to get a trace. Based on the limited scope
80- // of what we cover, we can just take the first trace from the list,
81- // or otherwise just the first trace:
82- container = gd . _fullData [ binding . traces !== null ? binding . traces [ 0 ] : 0 ] ;
83- } else if ( binding . type === 'layout' ) {
84- container = gd . _fullLayout ;
85- } else {
86- return false ;
87- }
88-
89- value = Lib . nestedProperty ( container , binding . prop ) . get ( ) ;
90-
91- obj = ret . cache [ binding . type ] = ret . cache [ binding . type ] || { } ;
92-
93- if ( obj . hasOwnProperty ( binding . prop ) ) {
94- if ( obj [ binding . prop ] !== value ) {
95- changed = true ;
96- }
97- }
98-
99- obj [ binding . prop ] = value ;
100-
101- if ( changed && onchange ) {
78+ if ( update . changed && onchange ) {
10279 // Disable checks for the duration of this command in order to avoid
10380 // infinite loops:
104- if ( ret . lookupTable [ value ] !== undefined ) {
81+ if ( ret . lookupTable [ update . value ] !== undefined ) {
10582 ret . disable ( ) ;
10683 Promise . resolve ( onchange ( {
107- value : value ,
84+ value : update . value ,
10885 type : binding . type ,
10986 prop : binding . prop ,
11087 traces : binding . traces ,
111- index : ret . lookupTable [ value ]
88+ index : ret . lookupTable [ update . value ]
11289 } ) ) . then ( ret . enable , ret . enable ) ;
11390 }
11491 }
11592
116- return changed ;
93+ return update . changed ;
11794 } ;
11895
11996 var checkEvents = [
@@ -260,7 +237,10 @@ function bindingValueHasChanged(gd, binding, cache) {
260237
261238 obj [ binding . prop ] = value ;
262239
263- return changed ;
240+ return {
241+ changed : changed ,
242+ value : value
243+ } ;
264244}
265245
266246/*
0 commit comments