##// END OF EJS Templates
Only send diff message if diff isn't corrupt....
Jonathan Frederic -
Show More
@@ -32,6 +32,7 b' function(WidgetManager, _, Backbone){'
32 // An ID unique to this model.
32 // An ID unique to this model.
33 // comm : Comm instance (optional)
33 // comm : Comm instance (optional)
34 this.widget_manager = widget_manager;
34 this.widget_manager = widget_manager;
35 this._set_calls = 0;
35 this.pending_msgs = 0;
36 this.pending_msgs = 0;
36 this.msg_throttle = 3;
37 this.msg_throttle = 3;
37 this.msg_buffer = null;
38 this.msg_buffer = null;
@@ -135,6 +136,12 b' function(WidgetManager, _, Backbone){'
135 return callbacks;
136 return callbacks;
136 },
137 },
137
138
139 set: function(key, val, options) {
140 // Set a value.
141 this._set_calls++;
142 return WidgetModel.__super__.set.apply(this, arguments);
143 },
144
138 sync: function (method, model, options) {
145 sync: function (method, model, options) {
139 // Handle sync to the back-end. Called when a model.save() is called.
146 // Handle sync to the back-end. Called when a model.save() is called.
140
147
@@ -158,6 +165,7 b' function(WidgetManager, _, Backbone){'
158 }
165 }
159
166
160 // Only sync if there are attributes to send to the back-end.
167 // Only sync if there are attributes to send to the back-end.
168 attrs = this._pack_models(attrs);
161 if (_.size(attrs) > 0) {
169 if (_.size(attrs) > 0) {
162
170
163 // If this message was sent via backbone itself, it will not
171 // If this message was sent via backbone itself, it will not
@@ -197,13 +205,26 b' function(WidgetManager, _, Backbone){'
197 // Since the comm is a one-way communication, assume the message
205 // Since the comm is a one-way communication, assume the message
198 // arrived. Don't call success since we don't have a model back from the server
206 // arrived. Don't call success since we don't have a model back from the server
199 // this means we miss out on the 'sync' event.
207 // this means we miss out on the 'sync' event.
208 this._set_calls = 0;
200 },
209 },
201
210
202 save_changes: function(callbacks) {
211 save_changes: function(callbacks) {
203 // Push this model's state to the back-end
212 // Push this model's state to the back-end
204 //
213 //
205 // This invokes a Backbone.Sync.
214 // This invokes a Backbone.Sync.
206 this.save(this.changedAttributes(), {patch: true, callbacks: callbacks});
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 }
207 },
228 },
208
229
209 _pack_models: function(value) {
230 _pack_models: function(value) {
General Comments 0
You need to be logged in to leave comments. Login now