Skip to content

Commit ecf7998

Browse files
authored
Merge pull request #1298 from jasongrout/doublesync
Don’t buffer attributes that are being set from the kernel unless they changed
2 parents 55ab0a7 + ee7619c commit ecf7998

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

jupyter-js-widgets/src/widget.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,27 @@ class WidgetModel extends Backbone.Model {
276276

277277
// Backbone only remembers the diff of the most recent set()
278278
// operation. Calling set multiple times in a row results in a
279-
// loss of diff information. Here we keep our own running diff.
279+
// loss of change information. Here we keep our own running diff.
280280
//
281281
// We don't buffer the state set in the constructor (including
282282
// defaults), so we first check to see if we've initialized _buffered_state_diff.
283283
// which happens after the constructor sets attributes at creation.
284284
if (this._buffered_state_diff !== void 0) {
285-
this._buffered_state_diff = _.extend(this._buffered_state_diff, this.changedAttributes() || {});
285+
let attrs = this.changedAttributes() || {};
286+
287+
// The state_lock lists attributes that are currently being changed
288+
// right now from a kernel message. We don't want to send these
289+
// non-changes back to the kernel, so we delete them out of attrs if
290+
// they haven't changed from their state_lock value
291+
if (this.state_lock !== null) {
292+
for (const key of Object.keys(this.state_lock)) {
293+
if (attrs[key] === this.state_lock[key]) {
294+
delete attrs[key];
295+
}
296+
}
297+
}
298+
299+
this._buffered_state_diff = _.extend(this._buffered_state_diff, attrs);
286300
}
287301
return return_value;
288302
}

0 commit comments

Comments
 (0)