Create a :class:`WebModule` from a framework template This is useful for experimenting with component libraries that do not already support ReactPy's :ref:`Custom Javascript Component` interface. .. warning:: This approach is not recommended for use in a production setting bec
(
template: str,
package: str,
cdn: str = "https://esm.sh",
fallback: Any | None = None,
resolve_exports: bool | None = None,
resolve_exports_depth: int = 5,
unmount_before_update: bool = False,
)
| 77 | |
| 78 | |
| 79 | def module_from_template( |
| 80 | template: str, |
| 81 | package: str, |
| 82 | cdn: str = "https://esm.sh", |
| 83 | fallback: Any | None = None, |
| 84 | resolve_exports: bool | None = None, |
| 85 | resolve_exports_depth: int = 5, |
| 86 | unmount_before_update: bool = False, |
| 87 | ) -> WebModule: |
| 88 | """Create a :class:`WebModule` from a framework template |
| 89 | |
| 90 | This is useful for experimenting with component libraries that do not already |
| 91 | support ReactPy's :ref:`Custom Javascript Component` interface. |
| 92 | |
| 93 | .. warning:: |
| 94 | |
| 95 | This approach is not recommended for use in a production setting because the |
| 96 | framework templates may use unpinned dependencies that could change without |
| 97 | warning. It's best to author a module adhering to the |
| 98 | :ref:`Custom Javascript Component` interface instead. |
| 99 | |
| 100 | **Templates** |
| 101 | |
| 102 | - ``react``: for modules exporting React components |
| 103 | |
| 104 | Parameters: |
| 105 | template: |
| 106 | The name of the framework template to use with the given ``package``. |
| 107 | package: |
| 108 | The name of a package to load. May include a file extension (defaults to |
| 109 | ``.js`` if not given) |
| 110 | cdn: |
| 111 | Where the package should be loaded from. The CDN must distribute ESM modules |
| 112 | fallback: |
| 113 | What to temporarily display while the module is being loaded. |
| 114 | resolve_imports: |
| 115 | Whether to try and find all the named exports of this module. |
| 116 | resolve_exports_depth: |
| 117 | How deeply to search for those exports. |
| 118 | unmount_before_update: |
| 119 | Cause the component to be unmounted before each update. This option should |
| 120 | only be used if the imported package fails to re-render when props change. |
| 121 | Using this option has negative performance consequences since all DOM |
| 122 | elements must be changed on each render. See :issue:`461` for more info. |
| 123 | """ |
| 124 | warn( |
| 125 | "module_from_template() is deprecated due to instability - use the Javascript " |
| 126 | "Components API instead. This function will be removed in a future release.", |
| 127 | DeprecationWarning, |
| 128 | ) |
| 129 | template_name, _, template_version = template.partition("@") |
| 130 | template_version = "@" + template_version if template_version else "" |
| 131 | |
| 132 | # We do this since the package may be any valid URL path. Thus we may need to strip |
| 133 | # object parameters or query information so we save the resulting template under the |
| 134 | # correct file name. |
| 135 | package_name = urlparse(package).path |
| 136 |
nothing calls this directly
no test coverage detected