Skip to content

Commit

Permalink
Make sure the child promise is used consistently in the proxy widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout committed Feb 17, 2017
1 parent d13b9f9 commit e13f32e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions jupyter-js-widgets/src/widget_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ProxyModel extends CoreDOMWidgetModel {
_view_name: 'ProxyView',
_model_name: 'ProxyModel',
child: null
})
});
}

static serializers = _.extend({
Expand All @@ -133,7 +133,7 @@ class ProxyView extends DOMWidgetView {

_setElement(el: HTMLElement) {
if (this.el || el !== this.pWidget.node) {
// Boxes don't allow setting the element beyond the initial creation.
// Proxies don't allow setting the element beyond the initial creation.
throw new Error('Cannot reset the DOM element.');
}

Expand All @@ -151,7 +151,7 @@ class ProxyView extends DOMWidgetView {
}

render() {
var child_view = this.set_child(this.model.get('child'));
let child_view = this.set_child(this.model.get('child'));
this.listenTo(this.model, 'change:child', (model, value) => {
this.set_child(value);
});
Expand All @@ -168,18 +168,15 @@ class ProxyView extends DOMWidgetView {
}

set_child(value) {
if (this.child) {
this.child.remove();
}
this.child_promise = this.child_promise.then(()=> {
if (this.child) {
this.child.remove();
}
});
if (value) {
this.child_promise = this.child_promise.then(() => {
return this.create_child_view(value).then((view: DOMWidgetView) => {
if (!this.box) {
console.error('Widget place holder does not exist');
return;
}
this.pWidget.addWidget(view.pWidget);

this.child = view;
this.trigger('child:created');
}).catch(reject('Could not add child view to proxy', true));
Expand All @@ -190,7 +187,7 @@ class ProxyView extends DOMWidgetView {

pWidget: JupyterPhosphorPanelWidget;
/**
* The element that contains
* The element that contains the child
*/
box: HTMLElement;
/**
Expand Down

0 comments on commit e13f32e

Please sign in to comment.