##// END OF EJS Templates
Merge pull request #6463 from SylvainCorlay/bulk_update...
Jonathan Frederic -
r17928:90d2eed8 merge
parent child Browse files
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.key_value_lock = null;
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 WidgetModel.__super__.set.apply(that, [key, that._unpack_models(value)]);
87 obj[key] = that._unpack_models(state[key]);
88 } finally {
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.key_value_lock !== null) {
155 if (this.state_lock !== null) {
155 var key = this.key_value_lock[0];
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 if (attrs[key] === value) {
158 var key = keys[i];
158 delete attrs[key];
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