##// END OF EJS Templates
Keep a running diff instead of forcing a full state update
Jonathan Frederic -
Show More
@@ -32,7 +32,7 b' function(WidgetManager, _, Backbone){'
32 32 // An ID unique to this model.
33 33 // comm : Comm instance (optional)
34 34 this.widget_manager = widget_manager;
35 this._set_calls = 0;
35 this._buffered_state_diff = {};
36 36 this.pending_msgs = 0;
37 37 this.msg_throttle = 3;
38 38 this.msg_buffer = null;
@@ -138,8 +138,13 b' function(WidgetManager, _, Backbone){'
138 138
139 139 set: function(key, val, options) {
140 140 // Set a value.
141 this._set_calls++;
142 return WidgetModel.__super__.set.apply(this, arguments);
141 var return_value = WidgetModel.__super__.set.apply(this, arguments);
142
143 // Backbone only remembers the diff of the most recent set()
144 // opertation. Calling set multiple times in a row results in a
145 // loss of diff information. Here we keep our own running diff.
146 this._buffered_state_diff = $.extend(this._buffered_state_diff, this.changedAttributes() || {});
147 return return_value;
143 148 },
144 149
145 150 sync: function (method, model, options) {
@@ -205,26 +210,14 b' function(WidgetManager, _, Backbone){'
205 210 // Since the comm is a one-way communication, assume the message
206 211 // arrived. Don't call success since we don't have a model back from the server
207 212 // this means we miss out on the 'sync' event.
208 this._set_calls = 0;
213 this._buffered_state_diff = {};
209 214 },
210 215
211 216 save_changes: function(callbacks) {
212 217 // Push this model's state to the back-end
213 218 //
214 219 // This invokes a Backbone.Sync.
215
216 // Backbone only remembers the diff of the most recent set()
217 // opertation. Calling set multiple times in a row results in a
218 // loss of diff information which means we need to send a full
219 // state. If diffing is important to the user, model.set(...) should
220 // only be called once prior to a view.touch(). If multiple
221 // parameters need to be set, use the model.set({key1: val1, key2: val2, ...})
222 // signature.
223 if (self._set_calls <= 1) {
224 this.save(this.changedAttributes(), {patch: true, callbacks: callbacks});
225 } else {
226 this.save(null, {patch: false, callbacks: callbacks});
227 }
220 this.save(this._buffered_state_diff, {patch: true, callbacks: callbacks});
228 221 },
229 222
230 223 _pack_models: function(value) {
General Comments 0
You need to be logged in to leave comments. Login now