Show More
@@ -24,7 +24,7 b' define(["widgets/js/manager",' | |||||
24 | this._buffered_state_diff = {}; |
|
24 | this._buffered_state_diff = {}; | |
25 | this.pending_msgs = 0; |
|
25 | this.pending_msgs = 0; | |
26 | this.msg_buffer = null; |
|
26 | this.msg_buffer = null; | |
27 |
this. |
|
27 | this.state_lock = null; | |
28 | this.id = model_id; |
|
28 | this.id = model_id; | |
29 | this.views = []; |
|
29 | this.views = []; | |
30 |
|
30 | |||
@@ -80,15 +80,16 b' define(["widgets/js/manager",' | |||||
80 |
|
80 | |||
81 | apply_update: function (state) { |
|
81 | apply_update: function (state) { | |
82 | // Handle when a widget is updated via the python side. |
|
82 | // Handle when a widget is updated via the python side. | |
83 | var that = this; |
|
83 | this.state_lock = state; | |
84 | _.each(state, function(value, key) { |
|
84 | try { | |
85 | that.key_value_lock = [key, value]; |
|
85 | var that = this; | |
86 | try { |
|
86 | WidgetModel.__super__.set.apply(this, [Object.keys(state).reduce(function(obj, key) { | |
87 |
|
|
87 | obj[key] = that._unpack_models(state[key]); | |
88 |
|
|
88 | return obj; | |
89 | that.key_value_lock = null; |
|
89 | }, {})]); | |
90 |
|
|
90 | } finally { | |
91 | }); |
|
91 | this.state_lock = null; | |
|
92 | } | |||
92 | }, |
|
93 | }, | |
93 |
|
94 | |||
94 | _handle_status: function (msg, callbacks) { |
|
95 | _handle_status: function (msg, callbacks) { | |
@@ -151,11 +152,13 b' define(["widgets/js/manager",' | |||||
151 |
|
152 | |||
152 | // Delete any key value pairs that the back-end already knows about. |
|
153 | // Delete any key value pairs that the back-end already knows about. | |
153 | var attrs = (method === 'patch') ? options.attrs : model.toJSON(options); |
|
154 | var attrs = (method === 'patch') ? options.attrs : model.toJSON(options); | |
154 |
if (this. |
|
155 | if (this.state_lock !== null) { | |
155 |
var key = this. |
|
156 | var keys = Object.keys(this.state_lock); | |
156 | var value = this.key_value_lock[1]; |
|
157 | for (var i=0; i<keys.length; i++) { | |
157 |
|
|
158 | var key = keys[i]; | |
158 |
|
|
159 | if (attrs[key] === this.state_lock[key]) { | |
|
160 | delete attrs[key]; | |||
|
161 | } | |||
159 | } |
|
162 | } | |
160 | } |
|
163 | } | |
161 |
|
164 | |||
@@ -266,6 +269,19 b' define(["widgets/js/manager",' | |||||
266 | } |
|
269 | } | |
267 | }, |
|
270 | }, | |
268 |
|
271 | |||
|
272 | on_atomic_change: function(keys, callback, context) { | |||
|
273 | // on__atomic_change(["key1", "key2"], foo, context) differs from | |||
|
274 | // on("change:key1 change:key2", foo, context). | |||
|
275 | // If the widget attributes key1 and key2 are both modified, | |||
|
276 | // the second form will result in foo being called twice | |||
|
277 | // while the first will call foo only once. | |||
|
278 | this.on('change', function() { | |||
|
279 | if (keys.some(this.hasChanged, this)) { | |||
|
280 | callback.apply(context); | |||
|
281 | } | |||
|
282 | }, this); | |||
|
283 | ||||
|
284 | }, | |||
269 | }); |
|
285 | }); | |
270 | widgetmanager.WidgetManager.register_widget_model('WidgetModel', WidgetModel); |
|
286 | widgetmanager.WidgetManager.register_widget_model('WidgetModel', WidgetModel); | |
271 |
|
287 |
General Comments 0
You need to be logged in to leave comments.
Login now