@@ -67,53 +67,30 @@ exports.createCommandObserver = function(gd, container, commandList, onchange) {
67
67
// Determine whether there's anything to do for this binding:
68
68
69
69
if ( binding ) {
70
+ // Build the cache:
70
71
bindingValueHasChanged ( gd , binding , ret . cache ) ;
71
72
72
73
ret . check = function check ( ) {
73
74
if ( ! enabled ) return ;
74
75
75
- var container , value , obj ;
76
- var changed = false ;
76
+ var update = bindingValueHasChanged ( gd , binding , ret . cache ) ;
77
77
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 ) {
102
79
// Disable checks for the duration of this command in order to avoid
103
80
// infinite loops:
104
- if ( ret . lookupTable [ value ] !== undefined ) {
81
+ if ( ret . lookupTable [ update . value ] !== undefined ) {
105
82
ret . disable ( ) ;
106
83
Promise . resolve ( onchange ( {
107
- value : value ,
84
+ value : update . value ,
108
85
type : binding . type ,
109
86
prop : binding . prop ,
110
87
traces : binding . traces ,
111
- index : ret . lookupTable [ value ]
88
+ index : ret . lookupTable [ update . value ]
112
89
} ) ) . then ( ret . enable , ret . enable ) ;
113
90
}
114
91
}
115
92
116
- return changed ;
93
+ return update . changed ;
117
94
} ;
118
95
119
96
var checkEvents = [
@@ -260,7 +237,10 @@ function bindingValueHasChanged(gd, binding, cache) {
260
237
261
238
obj [ binding . prop ] = value ;
262
239
263
- return changed ;
240
+ return {
241
+ changed : changed ,
242
+ value : value
243
+ } ;
264
244
}
265
245
266
246
/*
0 commit comments