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