##// END OF EJS Templates
this.updating should be a key specific lock
Jonathan Frederic -
Show More
@@ -38,6 +38,7 function(widget_manager, underscore, backbone){
38 38 this.pending_msgs = 0;
39 39 this.msg_throttle = 3;
40 40 this.msg_buffer = null;
41 this.key_value_lock = null;
41 42 this.id = model_id;
42 43 this.views = [];
43 44
@@ -89,18 +90,20 function(widget_manager, underscore, backbone){
89 90
90 91 // Handle when a widget is updated via the python side.
91 92 apply_update: function (state) {
92 this.updating = true;
93 try {
93 //this.updating = true;
94 94 for (var key in state) {
95 95 if (state.hasOwnProperty(key)) {
96 var value = state[key];
97 this.key_value_lock = [key, value];
98 try {
96 99 this.set(key, state[key]);
100 } finally {
101 this.key_value_lock = null;
102 }
97 103 }
98 104 }
99 105 //TODO: are there callbacks that make sense in this case? If so, attach them here as an option
100 106 this.save();
101 } finally {
102 this.updating = false;
103 }
104 107 },
105 108
106 109
@@ -131,7 +134,6 function(widget_manager, underscore, backbone){
131 134 // Only send updated state if the state hasn't been changed
132 135 // during an update.
133 136 if (this.comm !== undefined) {
134 if (!this.updating) {
135 137 if (this.pending_msgs >= this.msg_throttle) {
136 138 // The throttle has been exceeded, buffer the current msg so
137 139 // it can be sent once the kernel has finished processing
@@ -141,7 +143,10 function(widget_manager, underscore, backbone){
141 143 this.msg_buffer = $.extend({}, model_json); // Copy
142 144 }
143 145 for (attr in options.attrs) {
144 this.msg_buffer[attr] = options.attrs[attr];
146 var value = options.attrs[attr];
147 if (this.key_value_lock === null || attr != this.key_value_lock[0] || value != this.key_value_lock[1]) {
148 this.msg_buffer[attr] = value;
149 }
145 150 }
146 151 } else {
147 152 this.msg_buffer = $.extend({}, model_json); // Copy
@@ -155,7 +160,10 function(widget_manager, underscore, backbone){
155 160 if (method =='patch') {
156 161 send_json = {};
157 162 for (attr in options.attrs) {
158 send_json[attr] = options.attrs[attr];
163 var value = options.attrs[attr];
164 if (this.key_value_lock === null || attr != this.key_value_lock[0] || value != this.key_value_lock[1]) {
165 send_json[attr] = value;
166 }
159 167 }
160 168 }
161 169
@@ -164,7 +172,6 function(widget_manager, underscore, backbone){
164 172 this.pending_msgs++;
165 173 }
166 174 }
167 }
168 175
169 176 // Since the comm is a one-way communication, assume the message
170 177 // arrived.
General Comments 0
You need to be logged in to leave comments. Login now