Skip to content

Commit 36b216c

Browse files
committed
rename and add docs for define_module widget
1 parent d054673 commit 36b216c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

idom/widgets/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .common import Import, import_module, hotswap
1+
from .common import Import, define_module, hotswap
22
from .display import display
33
from .inputs import Input
44
from .images import Image
@@ -8,7 +8,7 @@
88
"display",
99
"node",
1010
"Image",
11-
"import_module",
11+
"define_module",
1212
"hotswap",
1313
"html",
1414
"Input",

idom/widgets/common.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@
77
from idom.tools import Var
88

99

10-
def import_module(name: str, source: Any, raw: bool = False) -> "Import":
10+
def define_module(name: str, source: Any, raw: bool = False) -> "Import":
11+
"""Add a module to the client
12+
13+
Parameters:
14+
name:
15+
What the module will be named (excluding the ``.js`` file extension). This
16+
matters if you want to import this module from another later since this will
17+
be the filename the module is saved under.
18+
source:
19+
The module's source.
20+
raw:
21+
If false, then ``source`` should be a file path to the module's source.
22+
If true, this should be the literal source code for the module.
23+
24+
Returns:
25+
An :class:`Import` element for the newly defined module.
26+
"""
1127
if not raw:
1228
with open(str(source), "r") as f:
1329
source = f.read()

tests/test_browser/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from idom.widgets import Import, import_module
7+
from idom.widgets import Import, define_module
88
from idom import client
99

1010
HERE = Path(__file__).parent
@@ -30,7 +30,7 @@ def test_raise_on_missing_import_path():
3030

3131

3232
def test_custom_module(driver, display, victory):
33-
my_chart = import_module("my_chart", HERE / "my_chart.js")
33+
my_chart = define_module("my_chart", HERE / "my_chart.js")
3434

3535
display(my_chart.Chart)
3636

0 commit comments

Comments
 (0)