Skip to content

Commit 34d4a87

Browse files
committed
update usages
1 parent 6401120 commit 34d4a87

16 files changed

+83
-133
lines changed

docs/examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def Wrapper():
122122
def PrintView():
123123
text, set_text = idom.hooks.use_state(print_buffer.getvalue())
124124
print_buffer.set_callback(set_text)
125-
return idom.html.pre({"class": "printout"}, text) if text else idom.html.div()
125+
return idom.html.pre(text, class_="printout") if text else idom.html.div()
126126

127127
return Wrapper()
128128

requirements/pkg-deps.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ requests >=2
77
colorlog >=6
88
asgiref >=3
99
lxml >=4
10-
typer >=8, <9
10+
click >=8, <9

src/idom/core/vdom.py

+12-27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4-
from functools import wraps
5-
from typing import Any, Mapping, TypeVar, cast
4+
from typing import Any, Mapping, cast
65
from warnings import warn
76

87
from fastjsonschema import compile as compile_json_schema
@@ -130,31 +129,6 @@ def is_vdom(value: Any) -> bool:
130129
)
131130

132131

133-
_T = TypeVar("_T")
134-
135-
136-
def _help_message(func: _T) -> _T:
137-
@wraps(func)
138-
def wrapper(*args, **kwargs):
139-
try:
140-
return func(*args, **kwargs)
141-
except TypeError: # pragma: no cover
142-
warn(
143-
(
144-
"Element constructor signatures have changed! A CLI tool for "
145-
"automatically updating code to the latest API has been provided "
146-
"with this release of IDOM (e.g. 'idom update-html-usages'). For "
147-
"start a discussion if you need help transitioning to this new "
148-
"interface: https://github.com/idom-team/idom/discussions/new?category=question"
149-
),
150-
UserWarning,
151-
)
152-
raise
153-
154-
return wrapper
155-
156-
157-
@_help_message
158132
def vdom(
159133
tag: str, *children: VdomChild, key: Key | None = None, **attributes: Any
160134
) -> VdomDict:
@@ -182,6 +156,17 @@ def vdom(
182156

183157
children: list[VdomChild] = []
184158
for child in children:
159+
if isinstance(child, dict) and "tagName" not in child:
160+
warn(
161+
(
162+
"Element constructor signatures have changed! A CLI tool for "
163+
"automatically updating code to the latest API has been provided "
164+
"with this release of IDOM (e.g. 'idom update-html-usages'). For "
165+
"start a discussion if you need help transitioning to this new "
166+
"interface: https://github.com/idom-team/idom/discussions/new?category=question"
167+
),
168+
UserWarning,
169+
)
185170
if _is_single_child(child):
186171
children.append(child)
187172
else:

src/idom/sample.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
@component
99
def SampleApp() -> VdomDict:
1010
return html.div(
11-
{"id": "sample", "style": {"padding": "15px"}},
1211
html.h1("Sample Application"),
1312
html.p(
1413
"This is a basic application made with IDOM. Click ",
15-
html.a(
16-
{"href": "https://pypi.org/project/idom/", "target": "_blank"},
17-
"here",
18-
),
14+
html.a("here", href="https://pypi.org/project/idom/", target="_blank"),
1915
" to learn more.",
2016
),
17+
id="sample",
18+
style={"padding": "15px"},
2119
)

tests/test_backend/test__common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ def test_catch_unsafe_relative_path_traversal(tmp_path, bad_path):
4444
),
4545
(
4646
html.head(
47-
html.meta({"charset": "utf-8"}),
47+
html.meta(charset="utf-8"),
4848
html.title("example"),
4949
),
5050
# we strip the head element
5151
'<meta charset="utf-8"><title>example</title>',
5252
),
5353
(
5454
html._(
55-
html.meta({"charset": "utf-8"}),
55+
html.meta(charset="utf-8"),
5656
html.title("example"),
5757
),
5858
'<meta charset="utf-8"><title>example</title>',
5959
),
6060
(
6161
[
62-
html.meta({"charset": "utf-8"}),
62+
html.meta(charset="utf-8"),
6363
html.title("example"),
6464
],
6565
'<meta charset="utf-8"><title>example</title>',

tests/test_backend/test_all.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def display(page, request):
3939
async def test_display_simple_hello_world(display: DisplayFixture):
4040
@idom.component
4141
def Hello():
42-
return idom.html.p({"id": "hello"}, ["Hello World"])
42+
return idom.html.p(["Hello World"], id="hello")
4343

4444
await display.show(Hello)
4545

@@ -56,11 +56,9 @@ async def test_display_simple_click_counter(display: DisplayFixture):
5656
def Counter():
5757
count, set_count = idom.hooks.use_state(0)
5858
return idom.html.button(
59-
{
60-
"id": "counter",
61-
"onClick": lambda event: set_count(lambda old_count: old_count + 1),
62-
},
6359
f"Count: {count}",
60+
id="counter",
61+
on_click=lambda event: set_count(lambda old_count: old_count + 1),
6462
)
6563

6664
await display.show(Counter)
@@ -85,7 +83,7 @@ async def test_use_connection(display: DisplayFixture):
8583
@idom.component
8684
def ShowScope():
8785
conn.current = idom.use_connection()
88-
return html.pre({"id": "scope"}, str(conn.current))
86+
return html.pre(str(conn.current), id="scope")
8987

9088
await display.show(ShowScope)
9189

@@ -99,7 +97,7 @@ async def test_use_scope(display: DisplayFixture):
9997
@idom.component
10098
def ShowScope():
10199
scope.current = idom.use_scope()
102-
return html.pre({"id": "scope"}, str(scope.current))
100+
return html.pre(str(scope.current), id="scope")
103101

104102
await display.show(ShowScope)
105103

@@ -147,7 +145,7 @@ async def test_use_request(display: DisplayFixture, hook_name):
147145
@idom.component
148146
def ShowRoute():
149147
hook_val.current = hook()
150-
return html.pre({"id": "hook"}, str(hook_val.current))
148+
return html.pre(str(hook_val.current), id="hook")
151149

152150
await display.show(ShowRoute)
153151

tests/test_client.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def test_automatic_reconnect(browser: Browser):
2222

2323
@idom.component
2424
def OldComponent():
25-
return idom.html.p({"id": "old-component"}, "old")
25+
return idom.html.p("old", id="old-component")
2626

2727
async with AsyncExitStack() as exit_stack:
2828
server = await exit_stack.enter_async_context(BackendFixture(port=port))
@@ -43,7 +43,7 @@ def OldComponent():
4343
@idom.component
4444
def NewComponent():
4545
state, set_state.current = idom.hooks.use_state(0)
46-
return idom.html.p({"id": f"new-component-{state}"}, f"new-{state}")
46+
return idom.html.p(f"new-{state}", id=f"new-component-{state}")
4747

4848
async with AsyncExitStack() as exit_stack:
4949
server = await exit_stack.enter_async_context(BackendFixture(port=port))
@@ -76,12 +76,10 @@ def ButtonWithChangingColor():
7676
color_toggle, set_color_toggle = idom.hooks.use_state(True)
7777
color = "red" if color_toggle else "blue"
7878
return idom.html.button(
79-
{
80-
"id": "my-button",
81-
"onClick": lambda event: set_color_toggle(not color_toggle),
82-
"style": {"backgroundColor": color, "color": "white"},
83-
},
8479
f"color: {color}",
80+
id="my-button",
81+
on_click=lambda event: set_color_toggle(not color_toggle),
82+
style={"backgroundColor": color, "color": "white"},
8583
)
8684

8785
await display.show(ButtonWithChangingColor)
@@ -117,7 +115,7 @@ async def handle_change(event):
117115
await asyncio.sleep(delay)
118116
set_value(event["target"]["value"])
119117

120-
return idom.html.input({"onChange": handle_change, "id": "test-input"})
118+
return idom.html.input(on_change=handle_change, id="test-input")
121119

122120
await display.show(SomeComponent)
123121

tests/test_core/test_component.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def ComponentWithVarArgsAndKwargs(*args, **kwargs):
4747
async def test_display_simple_hello_world(display: DisplayFixture):
4848
@idom.component
4949
def Hello():
50-
return idom.html.p({"id": "hello"}, ["Hello World"])
50+
return idom.html.p(["Hello World"], id="hello")
5151

5252
await display.show(Hello)
5353

@@ -58,10 +58,10 @@ async def test_pre_tags_are_rendered_correctly(display: DisplayFixture):
5858
@idom.component
5959
def PreFormated():
6060
return idom.html.pre(
61-
{"id": "pre-form-test"},
6261
idom.html.span("this", idom.html.span("is"), "some"),
6362
"pre-formated",
6463
" text",
64+
id="pre-form-test",
6565
)
6666

6767
await display.show(PreFormated)

tests/test_core/test_events.py

+9-21
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def Input():
151151
async def on_key_down(value):
152152
pass
153153

154-
return idom.html.input({"onKeyDown": on_key_down, "id": "input"})
154+
return idom.html.input(on_key_down=on_key_down, id="input")
155155

156156
await display.show(Input)
157157

@@ -170,9 +170,9 @@ async def on_click(event):
170170
set_clicked(True)
171171

172172
if not clicked:
173-
return idom.html.button({"onClick": on_click, "id": "click"}, ["Click Me!"])
173+
return idom.html.button(["Click Me!"], on_click=on_click, id="click")
174174
else:
175-
return idom.html.p({"id": "complete"}, ["Complete"])
175+
return idom.html.p(["Complete"], id="complete")
176176

177177
await display.show(Button)
178178

@@ -194,26 +194,14 @@ def outer_click_is_not_triggered(event):
194194
assert False
195195

196196
outer = idom.html.div(
197-
{
198-
"style": {
199-
"height": "35px",
200-
"width": "35px",
201-
"backgroundColor": "red",
202-
},
203-
"onClick": outer_click_is_not_triggered,
204-
"id": "outer",
205-
},
206197
idom.html.div(
207-
{
208-
"style": {
209-
"height": "30px",
210-
"width": "30px",
211-
"backgroundColor": "blue",
212-
},
213-
"onClick": inner_click_no_op,
214-
"id": "inner",
215-
},
198+
style={"height": "30px", "width": "30px", "backgroundColor": "blue"},
199+
on_click=inner_click_no_op,
200+
id="inner",
216201
),
202+
style={"height": "35px", "width": "35px", "backgroundColor": "red"},
203+
on_click=outer_click_is_not_triggered,
204+
id="outer",
217205
)
218206
return outer
219207

tests/test_core/test_hooks.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,14 @@ def TestComponent():
181181
render_count.current += 1
182182
return idom.html.div(
183183
idom.html.button(
184-
{
185-
"id": "r_1",
186-
"onClick": event_count_tracker(lambda event: set_state(r_1)),
187-
},
188184
"r_1",
185+
id="r_1",
186+
on_click=event_count_tracker(lambda event: set_state(r_1)),
189187
),
190188
idom.html.button(
191-
{
192-
"id": "r_2",
193-
"onClick": event_count_tracker(lambda event: set_state(r_2)),
194-
},
195189
"r_2",
190+
id="r_2",
191+
on_click=event_count_tracker(lambda event: set_state(r_2)),
196192
),
197193
f"Last state: {'r_1' if state is r_1 else 'r_2'}",
198194
)
@@ -237,9 +233,9 @@ async def on_change(event):
237233
set_message(event["target"]["value"])
238234

239235
if message is None:
240-
return idom.html.input({"id": "input", "onChange": on_change})
236+
return idom.html.input(id="input", on_change=on_change)
241237
else:
242-
return idom.html.p({"id": "complete"}, ["Complete"])
238+
return idom.html.p(["Complete"], id="complete")
243239

244240
await display.show(Input)
245241

@@ -261,13 +257,9 @@ def double_set_state(event):
261257
set_state_2(state_2 + 1)
262258

263259
return idom.html.div(
264-
idom.html.div(
265-
{"id": "first", "data-value": state_1}, f"value is: {state_1}"
266-
),
267-
idom.html.div(
268-
{"id": "second", "data-value": state_2}, f"value is: {state_2}"
269-
),
270-
idom.html.button({"id": "button", "onClick": double_set_state}, "click me"),
260+
idom.html.div(f"value is: {state_1}", id="first", data_value=state_1),
261+
idom.html.div(f"value is: {state_2}", id="second", data_value=state_2),
262+
idom.html.button("click me", id="button", on_click=double_set_state),
271263
)
272264

273265
await display.show(SomeComponent)

0 commit comments

Comments
 (0)