Skip to content

Commit 0a41ca3

Browse files
committed
test module_name_suffix
1 parent 98d86b1 commit 0a41ca3

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

docs/source/_static/custom.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1644,22 +1644,27 @@ function ImportedElement({ model }) {
16441644
}
16451645
}
16461646

1647-
function RenderImportedElement() {
1647+
function RenderImportedElement({ model, importSource }) {
16481648
react.useContext(LayoutConfigContext);
16491649
const mountPoint = react.useRef(null);
16501650
const sourceBinding = react.useRef(null);
16511651

16521652
react.useEffect(() => {
16531653
sourceBinding.current = importSource.bind(mountPoint.current);
1654-
return () => {
1655-
sourceBinding.current.unmount();
1656-
};
1654+
if (!importSource.data.unmountBeforeUpdate) {
1655+
return sourceBinding.current.unmount;
1656+
}
16571657
}, []);
16581658

16591659
// this effect must run every time in case the model has changed
1660-
react.useEffect(() => sourceBinding.current.render(model));
1661-
1660+
react.useEffect(() => {
1661+
sourceBinding.current.render(model);
1662+
if (importSource.data.unmountBeforeUpdate) {
1663+
return sourceBinding.current.unmount;
1664+
}
1665+
});
16621666

1667+
return html`<div ref=${mountPoint} />`;
16631668
}
16641669

16651670
function elementChildren(modelChildren) {
@@ -1717,6 +1722,7 @@ function loadImportSource$1(config, importSource) {
17171722
.then((module) => {
17181723
if (typeof module.bind == "function") {
17191724
return {
1725+
data: importSource,
17201726
bind: (node) => {
17211727
const binding = module.bind(node, config);
17221728
if (

tests/test_web/test_utils.py

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import responses
55

66
from idom.web.utils import (
7+
module_name_suffix,
78
resolve_module_exports_from_file,
89
resolve_module_exports_from_source,
910
resolve_module_exports_from_url,
@@ -13,6 +14,23 @@
1314
JS_FIXTURES_DIR = Path(__file__).parent / "js_fixtures"
1415

1516

17+
@pytest.mark.parametrize(
18+
"name, suffix",
19+
[
20+
("module", ".js"),
21+
("module.ext", ".ext"),
22+
("[email protected]", ".js"),
23+
("[email protected]", ".ext"),
24+
("@namespace/module", ".js"),
25+
("@namespace/module.ext", ".ext"),
26+
("@namespace/[email protected]", ".js"),
27+
("@namespace/[email protected]", ".ext"),
28+
],
29+
)
30+
def test_module_name_suffix(name, suffix):
31+
assert module_name_suffix(name) == suffix
32+
33+
1634
@responses.activate
1735
def test_resolve_module_exports_from_file(caplog):
1836
responses.add(

0 commit comments

Comments
 (0)