Skip to content

Commit 4751ab1

Browse files
committed
changelog + add dynamic default export
1 parent 20c2655 commit 4751ab1

File tree

8 files changed

+22
-58
lines changed

8 files changed

+22
-58
lines changed

docs/source/about/changelog.rst

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ Unreleased
3636
- ``ServerFixture -> BackendFixture``
3737
- ``DisplayFixture.server -> DisplayFixture.backend``
3838

39+
- :pull:`765` - ``exports_default`` parameter is not longer required for
40+
``module_from_template`` when exporting ``default``.
41+
42+
**Added**
43+
44+
- :pull:`765` - ability to specify versions with module templates (e.g.
45+
``module_from_template("react@^17.0.0", ...)``).
46+
3947

4048
v0.38.1
4149
-------

docs/source/reference/_examples/network_graph.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55

66
react_cytoscapejs = idom.web.module_from_template(
7-
# we need to use this template because react-cytoscapejs uses a default export
87
"react",
98
"react-cytoscapejs",
10-
exports_default=True,
119
fallback="⌛",
1210
)
1311
Cytoscape = idom.web.export(react_cytoscapejs, "default")

src/idom/web/module.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def module_from_template(
7979
package: str,
8080
cdn: str = "https://esm.sh",
8181
fallback: Optional[Any] = None,
82-
exports_default: bool = False,
8382
resolve_exports: bool = IDOM_DEBUG_MODE.current,
8483
resolve_exports_depth: int = 5,
8584
unmount_before_update: bool = False,
@@ -110,8 +109,6 @@ def module_from_template(
110109
Where the package should be loaded from. The CDN must distribute ESM modules
111110
fallback:
112111
What to temporarilly display while the module is being loaded.
113-
exports_default:
114-
Whether the module has a default export.
115112
resolve_imports:
116113
Whether to try and find all the named exports of this module.
117114
resolve_exports_depth:
@@ -133,11 +130,7 @@ def module_from_template(
133130
# downstream code assumes no trailing slash
134131
cdn = cdn.rstrip("/")
135132

136-
template_file_name = (
137-
template_name
138-
+ (".default" if exports_default else "")
139-
+ module_name_suffix(package_name)
140-
)
133+
template_file_name = template_name + module_name_suffix(package_name)
141134

142135
template_file = Path(__file__).parent / "templates" / template_file_name
143136
if not template_file.exists():

src/idom/web/templates/react.default.js

-48
This file was deleted.

src/idom/web/templates/react.js

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ export * from "$CDN/$PACKAGE";
33
import * as React from "$CDN/react$VERSION";
44
import * as ReactDOM from "$CDN/react-dom$VERSION";
55

6+
export default ({ children, ...props }) => {
7+
const [{ component }, setComponent] = React.useState({});
8+
React.useEffect(() => {
9+
import("$CDN/$PACKAGE").then((module) => {
10+
// dynamically load the default export since we don't know if it's exported.
11+
setComponent({ component: module.default });
12+
});
13+
});
14+
return component
15+
? React.createElement(component, props, ...(children || []))
16+
: null;
17+
};
18+
619
export function bind(node, config) {
720
return {
821
create: (component, props, children) =>
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)