Show More
@@ -120,10 +120,15 b' function(WidgetManager, Underscore, Backbone){' | |||||
120 | } |
|
120 | } | |
121 | }, |
|
121 | }, | |
122 |
|
122 | |||
123 |
callbacks: function( |
|
123 | callbacks: function(view) { | |
124 | // Create msg callbacks for a comm msg. |
|
124 | // Create msg callbacks for a comm msg. | |
|
125 | var callbacks = this.widget_manager.callbacks(view); | |||
|
126 | ||||
|
127 | if (callbacks.iopub === undefined) { | |||
|
128 | callbacks.iopub = {}; | |||
|
129 | } | |||
|
130 | ||||
125 | var that = this; |
|
131 | var that = this; | |
126 | if (callbacks.iopub === undefined) {callbacks.iopub = {};} |
|
|||
127 | callbacks.iopub.status = function (msg) { |
|
132 | callbacks.iopub.status = function (msg) { | |
128 | that._handle_status(msg, callbacks); |
|
133 | that._handle_status(msg, callbacks); | |
129 | } |
|
134 | } | |
@@ -131,54 +136,57 b' function(WidgetManager, Underscore, Backbone){' | |||||
131 | }, |
|
136 | }, | |
132 |
|
137 | |||
133 | sync: function (method, model, options) { |
|
138 | sync: function (method, model, options) { | |
134 | var error = options.error || function() {console.error('Backbone sync error:', arguments);} |
|
139 | ||
|
140 | // Make sure a comm exists. | |||
|
141 | var error = options.error || function() { | |||
|
142 | console.error('Backbone sync error:', arguments); | |||
|
143 | } | |||
135 | if (this.comm === undefined) { |
|
144 | if (this.comm === undefined) { | |
136 | error(); |
|
145 | error(); | |
137 | return false; |
|
146 | return false; | |
138 | } |
|
147 | } | |
139 |
|
148 | |||
140 | var attrs = (method==='patch') ? options.attrs : model.toJSON(options); |
|
149 | // Delete any key value pairs that the back-end already knows about. | |
141 |
|
150 | var attrs = (method === 'patch') ? options.attrs : model.toJSON(options); | ||
142 | if (this.key_value_lock !== null) { |
|
151 | if (this.key_value_lock !== null) { | |
143 | var k = this.key_value_lock[0]; |
|
152 | var key = this.key_value_lock[0]; | |
144 | var v = this.key_value_lock[1]; |
|
153 | var value = this.key_value_lock[1]; | |
145 | if (attrs[k]===v) { |
|
154 | if (attrs[key] === value) { | |
146 | delete attrs[k]; |
|
155 | delete attrs[key]; | |
147 | } |
|
156 | } | |
148 | } |
|
157 | } | |
149 | if (_.size(attrs) == 0) { |
|
|||
150 | error(); |
|
|||
151 | return false; |
|
|||
152 | } |
|
|||
153 | var callbacks = model.callbacks(options.callbacks || {}); |
|
|||
154 | if (this.pending_msgs >= this.msg_throttle) { |
|
|||
155 | // The throttle has been exceeded, buffer the current msg so |
|
|||
156 | // it can be sent once the kernel has finished processing |
|
|||
157 | // some of the existing messages. |
|
|||
158 |
|
||||
159 | // combine updates if it is a 'patch' sync, otherwise replace updates |
|
|||
160 | switch (method) { |
|
|||
161 | case 'patch': |
|
|||
162 | this.msg_buffer = _.extend(this.msg_buffer || {}, attrs); |
|
|||
163 | break; |
|
|||
164 | case 'update': |
|
|||
165 | this.msg_buffer = attrs; |
|
|||
166 | break; |
|
|||
167 | default: |
|
|||
168 | error(); |
|
|||
169 | return false; |
|
|||
170 | } |
|
|||
171 | this.msg_buffer_callbacks = callbacks; |
|
|||
172 |
|
158 | |||
173 | } else { |
|
159 | // Only sync if there are attributes to send to the back-end. | |
174 | // We haven't exceeded the throttle, send the message like |
|
160 | if (_.size(attrs) !== 0) { | |
175 | // normal. If this is a patch operation, just send the |
|
161 | var callbacks = options.callbacks || {}; | |
176 | // changes. |
|
162 | if (this.pending_msgs >= this.msg_throttle) { | |
177 | var data = {method: 'backbone', sync_data: attrs}; |
|
163 | // The throttle has been exceeded, buffer the current msg so | |
178 | this.comm.send(data, callbacks); |
|
164 | // it can be sent once the kernel has finished processing | |
179 |
|
|
165 | // some of the existing messages. | |
|
166 | ||||
|
167 | // Combine updates if it is a 'patch' sync, otherwise replace updates | |||
|
168 | switch (method) { | |||
|
169 | case 'patch': | |||
|
170 | this.msg_buffer = _.extend(this.msg_buffer || {}, attrs); | |||
|
171 | break; | |||
|
172 | case 'update': | |||
|
173 | this.msg_buffer = attrs; | |||
|
174 | break; | |||
|
175 | default: | |||
|
176 | error(); | |||
|
177 | return false; | |||
|
178 | } | |||
|
179 | this.msg_buffer_callbacks = callbacks; | |||
|
180 | ||||
|
181 | } else { | |||
|
182 | // We haven't exceeded the throttle, send the message like | |||
|
183 | // normal. If this is a patch operation, just send the | |||
|
184 | // changes. | |||
|
185 | var data = {method: 'backbone', sync_data: attrs}; | |||
|
186 | this.comm.send(data, callbacks); | |||
|
187 | this.pending_msgs++; | |||
|
188 | } | |||
180 | } |
|
189 | } | |
181 |
|
||||
182 | // Since the comm is a one-way communication, assume the message |
|
190 | // Since the comm is a one-way communication, assume the message | |
183 | // arrived. Don't call success since we don't have a model back from the server |
|
191 | // arrived. Don't call success since we don't have a model back from the server | |
184 | // this means we miss out on the 'sync' event. |
|
192 | // this means we miss out on the 'sync' event. | |
@@ -293,7 +301,7 b' function(WidgetManager, Underscore, Backbone){' | |||||
293 |
|
301 | |||
294 | callbacks: function(){ |
|
302 | callbacks: function(){ | |
295 | // Create msg callbacks for a comm msg. |
|
303 | // Create msg callbacks for a comm msg. | |
296 |
return this.model. |
|
304 | return this.model.callbacks(this); | |
297 | }, |
|
305 | }, | |
298 |
|
306 | |||
299 | render: function(){ |
|
307 | render: function(){ |
General Comments 0
You need to be logged in to leave comments.
Login now