Skip to content

Commit

Permalink
refactor: directly render vue tree if root view is a ipyvue widget
Browse files Browse the repository at this point in the history
Do not include a div in between temporarily. Since the widget view
is created before we try to render the the upyter-widget-mount-point
we do not need to get it asynchrounously via promises.
  • Loading branch information
maartenbreddels committed Nov 22, 2023
1 parent a789fb3 commit c9e8cc8
Showing 1 changed file with 14 additions and 35 deletions.
49 changes: 14 additions & 35 deletions solara/server/static/main-vuetify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

const widgetViews = {};
var jupyterWidgetMountPoint = {
data() {
return {
Expand All @@ -8,25 +9,21 @@ var jupyterWidgetMountPoint = {
},
props: ['mount-id'],
created() {
requestWidget(this.mountId);
},
mounted() {
const vue3 = Vue.version.startsWith('3');
requestWidget(this.mountId)
.then(widgetView => {
if (['VuetifyView', 'VuetifyTemplateView'].includes(widgetView.model.get('_view_name'))) {
this.renderFn = createElement => widgetView.vueRender(createElement);
} else {
while (this.$el.firstChild) {
this.$el.removeChild(this.$el.firstChild);
}

requirejs(['@jupyter-widgets/base'], widgets =>
widgets.JupyterPhosphorWidget.attach(widgetView.pWidget, this.$el)
);
const maybeCreateRenderFn = (widgetView) => {
if (['VuetifyView', 'VuetifyTemplateView'].includes(widgetView.model.get('_view_name'))) {
this.renderFn = createElement => widgetView.vueRender(createElement);
} else {
while (this.$el.firstChild) {
this.$el.removeChild(this.$el.firstChild);
}

requirejs(['@jupyter-widgets/base'], widgets =>
widgets.JupyterPhosphorWidget.attach(widgetView.pWidget, this.$el)
);
}
);
}
maybeCreateRenderFn(widgetViews[this.mountId]);
},
render(createElement) {
// in vue3 we have Vue.h, otherwise fall back to createElement (vue2)
Expand All @@ -43,24 +40,6 @@ var jupyterWidgetMountPoint = {
}
};

const widgetResolveFns = {};
const widgetPromises = {};

function provideWidget(mountId, widgetView) {
if (widgetResolveFns[mountId]) {
widgetResolveFns[mountId](widgetView);
} else {
widgetPromises[mountId] = Promise.resolve(widgetView);
}
}

function requestWidget(mountId) {
if (!widgetPromises[mountId]) {
widgetPromises[mountId] = new Promise(resolve => widgetResolveFns[mountId] = resolve);
}
return widgetPromises[mountId];
}

function injectDebugMessageInterceptor(kernel) {
const _original_handle_message = kernel._handleMessage.bind(kernel)
kernel._handleMessage = ((msg) => {
Expand Down Expand Up @@ -242,7 +221,7 @@ async function solaraMount(widgetManager, mountId, modelId) {
const model = await modelPromise;
if (model.model_id == modelId) {
const view = await widgetManager.create_view(model);
provideWidget(mountId, view);
widgetViews[mountId] = view;
}
}));
app.$data.loadingPercentage = 0;
Expand Down

0 comments on commit c9e8cc8

Please sign in to comment.