Skip to content

Commit 5eb7afd

Browse files
fix: avoid using a global force_load widget
1 parent 7ae2191 commit 5eb7afd

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

ipyvue/ForceLoad.py

-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ class ForceLoad(DOMWidget):
77
_model_name = Unicode("ForceLoadModel").tag(sync=True)
88
_model_module = Unicode("jupyter-vue").tag(sync=True)
99
_model_module_version = Unicode(semver).tag(sync=True)
10-
11-
12-
force_load_instance = ForceLoad()

ipyvue/VueTemplateWidget.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
2-
from traitlets import Any, Unicode, List, Dict, Union, Instance
2+
from traitlets import Any, Unicode, List, Dict, Union, Instance, default
33
from ipywidgets import DOMWidget
44
from ipywidgets.widgets.widget import widget_serialization
55

66
from .Template import Template, get_template
77
from ._version import semver
8-
from .ForceLoad import force_load_instance
8+
from .ForceLoad import ForceLoad
9+
from .util import singleton
910
import inspect
1011
from importlib import import_module
1112

@@ -94,12 +95,15 @@ class VueTemplate(DOMWidget, Events):
9495
"to_json": _class_to_json,
9596
}
9697

97-
# Force the loading of jupyter-vue before dependent extensions when in a static
98-
# context (embed, voila)
99-
_jupyter_vue = Any(force_load_instance, read_only=True).tag(
98+
# see VueWidget
99+
_jupyter_vue = Instance(ForceLoad, read_only=True).tag(
100100
sync=True, **widget_serialization
101101
)
102102

103+
@default("_jupyter_vue")
104+
def _default_jupyter_vue(self):
105+
return singleton(ForceLoad)
106+
103107
_model_name = Unicode("VueTemplateModel").tag(sync=True)
104108

105109
_view_name = Unicode("VueView").tag(sync=True)

ipyvue/VueWidget.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from traitlets import Unicode, Instance, Union, List, Any, Dict
21
from ipywidgets import DOMWidget
3-
from ipywidgets.widgets.widget_layout import Layout
4-
from ipywidgets.widgets.widget import widget_serialization, CallbackDispatcher
52
from ipywidgets.widgets.trait_types import InstanceDict
3+
from ipywidgets.widgets.widget import CallbackDispatcher, widget_serialization
4+
from ipywidgets.widgets.widget_layout import Layout
5+
from traitlets import Any, Dict, Instance, List, Unicode, Union, default
66

77
from ._version import semver
8-
from .ForceLoad import force_load_instance
8+
from .ForceLoad import ForceLoad
9+
from .util import singleton
910

1011

1112
class ClassList:
@@ -138,10 +139,18 @@ class VueWidget(DOMWidget, Events):
138139

139140
# Force the loading of jupyter-vue before dependent extensions when in a static
140141
# context (embed, voila)
141-
_jupyter_vue = Any(force_load_instance, read_only=True).tag(
142+
# this happens when e.g. jupyter-vuedraggable requires jupyter-vue, but it is not
143+
# loaded yet (via a widget creation). This does not trigger the library loading
144+
# via the widget manager, but straight through requirejs
145+
146+
_jupyter_vue = Instance(ForceLoad, read_only=True).tag(
142147
sync=True, **widget_serialization
143148
)
144149

150+
@default("_jupyter_vue")
151+
def _default_jupyter_vue(self):
152+
return singleton(ForceLoad)
153+
145154
_model_name = Unicode("VueModel").tag(sync=True)
146155

147156
_view_name = Unicode("VueView").tag(sync=True)

0 commit comments

Comments
 (0)