Skip to content

Commit 9494bc0

Browse files
committed
pass children as props to mount()
1 parent 7ccc534 commit 9494bc0

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

docs/source/faq.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ similar to those of standard event handlers (e.g. ``onClick``) will operate as e
3030

3131
However, if you import a pre-built :ref:`Custom Javascript Component <Custom Javascript Components>`
3232
then, so long as the bundle has be defined appropriately, any component can be made to
33-
work, even those that don't rely on React. However these components cannot have
34-
children.
33+
work, even those that don't rely on React.
3534

3635

3736
How does IDOM communicate with the client?

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ function mountImportSource(element, module, model, config) {
142142
if (model.children) {
143143
console.error("Mount function does not support children");
144144
}
145-
module.mount(
146-
element,
147-
module[model.tagName],
148-
elementAttributes(model, config.sendEvent)
149-
);
145+
const props = elementAttributes(model, config.sendEvent);
146+
if (model.children) {
147+
props.children = model.children;
148+
}
149+
module.mount(element, module[model.tagName], props);
150150
} else {
151151
reactDOM.render(
152152
react.createElement(

src/idom/client/module.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
def declare(
135135
self,
136136
name: str,
137-
has_children: Optional[bool] = None,
137+
has_children: bool = True,
138138
fallback: Optional[str] = None,
139139
) -> Import:
140140
"""Return an :class:`Import` for the given :class:`Module` and ``name``
@@ -189,7 +189,7 @@ def __init__(
189189
self,
190190
module: str,
191191
name: str,
192-
has_children: Optional[bool] = None,
192+
has_children: bool = True,
193193
has_mount: bool = False,
194194
fallback: Optional[str] = None,
195195
) -> None:
@@ -200,17 +200,6 @@ def __init__(
200200
raise RuntimeError(
201201
f"{IDOM_CLIENT_MODULES_MUST_HAVE_MOUNT} is set and {module} has no mount"
202202
)
203-
204-
if has_mount:
205-
if has_children is True:
206-
raise ValueError(
207-
f"Components of {module!r} do not support "
208-
"children because has_mount=True"
209-
)
210-
has_children = False
211-
else:
212-
has_children = bool(has_children)
213-
214203
self._name = name
215204
self._constructor = make_vdom_constructor(name, has_children)
216205
self._import_source = ImportSourceDict(

tests/test_client/test_module.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ def test_idom_client_modules_must_have_mount():
105105
IDOM_CLIENT_MODULES_MUST_HAVE_MOUNT.current = old_opt
106106

107107

108-
def test_no_children_if_import_has_mount():
109-
with pytest.raises(ValueError, match="do not support children"):
110-
idom.Import(
111-
"https://some.url",
112-
"SomeComponent",
113-
has_children=True,
114-
has_mount=True,
115-
fallback=None,
116-
)
117-
118-
119108
def test_module_must_export_mount_if_has_mount_is_set():
120109
with pytest.raises(ValueError, match="does not export 'mount' but has_mount=True"):
121110
idom.Module(

0 commit comments

Comments
 (0)