##// END OF EJS Templates
optimization of WidgetModel.apply_update
sylvain.corlay -
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
@@ -78,15 +78,16 b' define(["widgets/js/manager",'
78
78
79 apply_update: function (state) {
79 apply_update: function (state) {
80 // Handle when a widget is updated via the python side.
80 // Handle when a widget is updated via the python side.
81 var that = this;
81 this.state_lock = state;
82 _.each(state, function(value, key) {
82 try {
83 that.key_value_lock = [key, value];
83 var that = this;
84 try {
84 WidgetModel.__super__.set.apply(this, [Object.keys(state).reduce(function(obj, key) {
85 WidgetModel.__super__.set.apply(that, [key, that._unpack_models(value)]);
85 obj[key] = that._unpack_models(state[key]);
86 } finally {
86 return obj;
87 that.key_value_lock = null;
87 }, {})]);
88 }
88 } finally {
89 });
89 this.state_lock = null;
90 }
90 },
91 },
91
92
92 _handle_status: function (msg, callbacks) {
93 _handle_status: function (msg, callbacks) {
@@ -149,12 +150,13 b' define(["widgets/js/manager",'
149
150
150 // Delete any key value pairs that the back-end already knows about.
151 // Delete any key value pairs that the back-end already knows about.
151 var attrs = (method === 'patch') ? options.attrs : model.toJSON(options);
152 var attrs = (method === 'patch') ? options.attrs : model.toJSON(options);
152 if (this.key_value_lock !== null) {
153 if (this.state_lock !== null) {
153 var key = this.key_value_lock[0];
154 var keys = Object.keys(this.state_lock);
154 var value = this.key_value_lock[1];
155 for (var i=0; i<keys.length; i++)
155 if (attrs[key] === value) {
156 var key = keys[i];
156 delete attrs[key];
157 if (attrs[key] === this.state_lock[key]) {
157 }
158 delete attrs[key];
159 }
158 }
160 }
159
161
160 // Only sync if there are attributes to send to the back-end.
162 // Only sync if there are attributes to send to the back-end.
General Comments 0
You need to be logged in to leave comments. Login now