Skip to content

Commit d55a28f

Browse files
committed
rename hasMount to exportsMount
also removes forgotten console.error for having children if exportsMount
1 parent 64fffb8 commit d55a28f

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

docs/source/faq.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Yes, but with some restrictions:
4949
1. The Javascript in question must be distributed as an ECMAScript Module
5050
(`ESM <https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/>`__)
5151
2. The module must export a ``mount(element, component, props)`` function
52-
3. Set ``has_mount=True`` when creating your :class:`~idom.client.module.Module`
52+
3. Set ``exports_mount=True`` when creating your :class:`~idom.client.module.Module`
5353
instance.
5454

5555
These restrictions apply because the Javascript from the CDN must be able to run

src/idom/client/app/packages/idom-client-react/src/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function ImportedElement({ model }) {
6969
mountImportSource(mountPoint.current, module, model, config);
7070
});
7171
});
72+
7273
return html`<div ref=${mountPoint} />`;
7374
}
7475

@@ -138,10 +139,7 @@ function eventHandler(sendEvent, eventSpec) {
138139
}
139140

140141
function mountImportSource(element, module, model, config) {
141-
if (model.importSource.hasMount) {
142-
if (model.children) {
143-
console.error("Mount function does not support children");
144-
}
142+
if (model.importSource.exportsMount) {
145143
const props = elementAttributes(model, config.sendEvent);
146144
if (model.children) {
147145
props.children = model.children;

src/idom/client/module.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def install(
3838
ignore_installed: bool = False,
3939
fallback: Optional[str] = None,
4040
# dynamically installed modules probably won't have a mount so we default to False
41-
has_mount: bool = False,
41+
exports_mount: bool = False,
4242
) -> Union[Module, List[Module]]:
4343
return_one = False
4444
if isinstance(packages, str):
@@ -51,10 +51,11 @@ def install(
5151
manage.build(packages, clean_build=False)
5252

5353
if return_one:
54-
return Module(pkg_names[0], fallback=fallback, has_mount=has_mount)
54+
return Module(pkg_names[0], fallback=fallback, exports_mount=exports_mount)
5555
else:
5656
return [
57-
Module(pkg, fallback=fallback, has_mount=has_mount) for pkg in pkg_names
57+
Module(pkg, fallback=fallback, exports_mount=exports_mount)
58+
for pkg in pkg_names
5859
]
5960

6061

@@ -74,7 +75,7 @@ class Module:
7475
``./some-other-installed-module.js``.
7576
fallack:
7677
What to display while the modules is being loaded.
77-
has_mount:
78+
exports_mount:
7879
Whether the module exports a ``mount`` function that allows components to
7980
be mounted directly to the DOM. Such a mount function enables greater
8081
flexibility in how custom components can be implemented.
@@ -90,7 +91,7 @@ class Module:
9091
"url",
9192
"fallback",
9293
"exports",
93-
"has_mount",
94+
"exports_mount",
9495
"check_exports",
9596
"_export_names",
9697
)
@@ -100,11 +101,11 @@ def __init__(
100101
url_or_name: str,
101102
source_file: Optional[Union[str, Path]] = None,
102103
fallback: Optional[str] = None,
103-
has_mount: bool = False,
104+
exports_mount: bool = False,
104105
check_exports: bool = True,
105106
) -> None:
106107
self.fallback = fallback
107-
self.has_mount = has_mount
108+
self.exports_mount = exports_mount
108109
self.check_exports = check_exports
109110

110111
self.exports: Set[str] = set()
@@ -126,9 +127,9 @@ def __init__(
126127
else:
127128
raise ValueError(f"{url_or_name!r} is not installed or is not a URL")
128129

129-
if check_exports and has_mount and "mount" not in self.exports:
130+
if check_exports and exports_mount and "mount" not in self.exports:
130131
raise ValueError(
131-
f"Module {url_or_name!r} does not export 'mount' but has_mount=True"
132+
f"Module {url_or_name!r} does not export 'mount' but exports_mount=True"
132133
)
133134

134135
def declare(
@@ -157,7 +158,7 @@ def declare(
157158
self.url,
158159
name,
159160
has_children=has_children,
160-
has_mount=self.has_mount,
161+
exports_mount=self.exports_mount,
161162
fallback=fallback or self.fallback,
162163
)
163164

@@ -190,10 +191,10 @@ def __init__(
190191
module: str,
191192
name: str,
192193
has_children: bool = True,
193-
has_mount: bool = False,
194+
exports_mount: bool = False,
194195
fallback: Optional[str] = None,
195196
) -> None:
196-
if IDOM_CLIENT_MODULES_MUST_HAVE_MOUNT.current and not has_mount:
197+
if IDOM_CLIENT_MODULES_MUST_HAVE_MOUNT.current and not exports_mount:
197198
# This check is not perfect since IDOM_CLIENT_MODULES_MUST_HAVE_MOUNT can be
198199
# set after Import instances have been constructed. A more comprehensive
199200
# check can be introduced if that is shown to be an issue in practice.
@@ -203,7 +204,7 @@ def __init__(
203204
self._name = name
204205
self._constructor = make_vdom_constructor(name, has_children)
205206
self._import_source = ImportSourceDict(
206-
source=module, fallback=fallback, hasMount=has_mount
207+
source=module, fallback=fallback, exportsMount=exports_mount
207208
)
208209

209210
def __call__(

src/idom/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def all_options() -> List[_Option[Any]]:
7676
7777
Client implementations that do not support dynamically installed modules can set this
7878
option to block the usages of components that are not mounted in isolation. More
79-
specifically, this requires the ``has_mount`` option of :class:`~idom.client.module.Module`
80-
to be ``True``.
79+
specifically, this requires the ``exports_mount`` option of
80+
:class:`~idom.client.module.Module` to be ``True``.
8181
"""
8282

8383
IDOM_FEATURE_INDEX_AS_DEFAULT_KEY = _Option(

src/idom/core/vdom.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"if": {"not": {"type": "null"}},
5959
"then": {"$ref": "#/definitions/elementOrString"},
6060
},
61-
"hasMount": {"type": "boolean"},
61+
"exportsMount": {"type": "boolean"},
6262
},
6363
"required": ["source"],
6464
},
@@ -84,7 +84,7 @@ def validate_vdom(value: Any) -> None:
8484
class ImportSourceDict(TypedDict):
8585
source: str
8686
fallback: Any
87-
hasMount: bool # noqa
87+
exportsMount: bool # noqa
8888

8989

9090
class _VdomDictOptional(TypedDict, total=False):

tests/test_client/test_app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_vanilla_js_component_with_mount(driver, display):
5050
vanilla_js_component = Module(
5151
"vanilla-js-component",
5252
source_file=HERE / "js" / "vanilla-js-component.js",
53-
has_mount=True,
53+
exports_mount=True,
5454
)
5555

5656
@idom.component

tests/test_client/test_module.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_any_relative_or_abolute_url_allowed():
3131
def test_module_import_repr():
3232
assert (
3333
repr(Module("/absolute/url/module").declare("SomeComponent"))
34-
== "Import(name='SomeComponent', source='/absolute/url/module', fallback=None, hasMount=False)"
34+
== "Import(name='SomeComponent', source='/absolute/url/module', fallback=None, exportsMount=False)"
3535
)
3636

3737

@@ -99,16 +99,18 @@ def test_idom_client_modules_must_have_mount():
9999
idom.Import(
100100
"https://some.url",
101101
"SomeComponent",
102-
has_mount=False,
102+
exports_mount=False,
103103
)
104104
finally:
105105
IDOM_CLIENT_MODULES_MUST_HAVE_MOUNT.current = old_opt
106106

107107

108-
def test_module_must_export_mount_if_has_mount_is_set():
109-
with pytest.raises(ValueError, match="does not export 'mount' but has_mount=True"):
108+
def test_module_must_export_mount_if_exports_mount_is_set():
109+
with pytest.raises(
110+
ValueError, match="does not export 'mount' but exports_mount=True"
111+
):
110112
idom.Module(
111113
"component-without-mount",
112114
source_file=JS_FIXTURES / "component-without-mount.js",
113-
has_mount=True,
115+
exports_mount=True,
114116
)

0 commit comments

Comments
 (0)