Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b7fe39c

Browse files
committedFeb 23, 2023
apply rewrites
1 parent 5277676 commit b7fe39c

File tree

23 files changed

+70
-72
lines changed

23 files changed

+70
-72
lines changed
 

‎docs/examples.py

Lines changed: 1 addition & 1 deletion
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({"class_": "printout"}, text) if text else idom.html.div()
126126

127127
return Wrapper()
128128

‎docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/moving_dot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ async def handle_pointer_move(event):
2222
"position": "relative",
2323
"height": "200px",
2424
"width": "100%",
25-
"backgroundColor": "white",
25+
"background_color": "white",
2626
},
2727
},
2828
html.div(
2929
{
3030
"style": {
3131
"position": "absolute",
32-
"backgroundColor": "red",
33-
"borderRadius": "50%",
32+
"background_color": "red",
33+
"border_radius": "50%",
3434
"width": "20px",
3535
"height": "20px",
3636
"left": "-10px",

‎docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/moving_dot_broken.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def handle_pointer_move(event):
2020
"position": "relative",
2121
"height": "200px",
2222
"width": "100%",
23-
"backgroundColor": "white",
23+
"background_color": "white",
2424
},
2525
},
2626
html.div(
2727
{
2828
"style": {
2929
"position": "absolute",
30-
"backgroundColor": "red",
31-
"borderRadius": "50%",
30+
"background_color": "red",
31+
"border_radius": "50%",
3232
"width": "20px",
3333
"height": "20px",
3434
"left": "-10px",

‎docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_remove.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def handle_click(event):
2424
"style": {
2525
"height": "30px",
2626
"width": "30px",
27-
"backgroundColor": "black"
27+
"background_color": "black"
2828
if index in selected_indices
2929
else "white",
3030
"outline": "1px solid grey",

‎docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def handle_click(event):
2121
"style": {
2222
"height": "30px",
2323
"width": "30px",
24-
"backgroundColor": "black"
24+
"background_color": "black"
2525
if index in selected_indices
2626
else "white",
2727
"outline": "1px solid grey",

‎docs/source/guides/adding-interactivity/multiple-state-updates/_examples/set_color_3_times.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ def handle_reset(event):
1515

1616
return html.div(
1717
html.button(
18-
{"on_click": handle_click, "style": {"backgroundColor": color}}, "Set Color"
18+
{"on_click": handle_click, "style": {"background_color": color}},
19+
"Set Color",
1920
),
2021
html.button(
21-
{"on_click": handle_reset, "style": {"backgroundColor": color}}, "Reset"
22+
{"on_click": handle_reset, "style": {"background_color": color}}, "Reset"
2223
),
2324
)
2425

‎docs/source/guides/adding-interactivity/responding-to-events/_examples/audio_player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def PlayDinosaurSound():
1010
idom.html.audio(
1111
{
1212
"controls": True,
13-
"onTimeUpdate": lambda e: set_event(e),
13+
"on_time_update": lambda e: set_event(e),
1414
"src": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
1515
}
1616
),

‎docs/source/guides/adding-interactivity/responding-to-events/_examples/stop_event_propagation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ def DivInDiv():
1010
div_in_div = html.div(
1111
{
1212
"on_click": lambda event: set_outer_count(outer_count + 1),
13-
"style": {"height": "100px", "width": "100px", "backgroundColor": "red"},
13+
"style": {"height": "100px", "width": "100px", "background_color": "red"},
1414
},
1515
html.div(
1616
{
1717
"on_click": event(
1818
lambda event: set_inner_count(inner_count + 1),
1919
stop_propagation=stop_propagatation,
2020
),
21-
"style": {"height": "50px", "width": "50px", "backgroundColor": "blue"},
21+
"style": {
22+
"height": "50px",
23+
"width": "50px",
24+
"background_color": "blue",
25+
},
2226
}
2327
),
2428
)

‎docs/source/reference/_examples/character_movement/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def Scene():
4242
"style": {
4343
"width": "200px",
4444
"height": "200px",
45-
"backgroundColor": "slategray",
45+
"background_color": "slategray",
4646
}
4747
},
4848
image(

‎docs/source/reference/_examples/click_count.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ def ClickCount():
66
count, set_count = idom.hooks.use_state(0)
77

88
return idom.html.button(
9-
{"onClick": lambda event: set_count(count + 1)},
10-
[f"Click count: {count}"],
9+
{"on_click": lambda event: set_count(count + 1)}, [f"Click count: {count}"]
1110
)
1211

1312

‎docs/source/reference/_examples/matplotlib_plot.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def del_input():
3939
return idom.html.div(
4040
idom.html.div(
4141
"add/remove term:",
42-
idom.html.button({"onClick": lambda event: add_input()}, "+"),
43-
idom.html.button({"onClick": lambda event: del_input()}, "-"),
42+
idom.html.button({"on_click": lambda event: add_input()}, "+"),
43+
idom.html.button({"on_click": lambda event: del_input()}, "-"),
4444
),
4545
inputs,
4646
)
@@ -65,12 +65,7 @@ def poly_coef_input(index, callback):
6565
" × X",
6666
idom.html.sup(index),
6767
),
68-
idom.html.input(
69-
{
70-
"type": "number",
71-
"onChange": callback,
72-
},
73-
),
68+
idom.html.input({"type": "number", "on_change": callback}),
7469
)
7570

7671

‎docs/source/reference/_examples/simple_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def update_value(value):
8383
set_value_callback(value)
8484

8585
return idom.html.fieldset(
86-
{"class": "number-input-container"},
86+
{"class_": "number-input-container"},
8787
idom.html.legend({"style": {"font-size": "medium"}}, label),
8888
Input(update_value, "number", value, attributes=attrs, cast=float),
8989
Input(update_value, "range", value, attributes=attrs, cast=float),

‎docs/source/reference/_examples/slideshow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def next_image(event):
1212
{
1313
"src": f"https://picsum.photos/id/{index}/800/300",
1414
"style": {"cursor": "pointer"},
15-
"onClick": next_image,
15+
"on_click": next_image,
1616
}
1717
)
1818

‎docs/source/reference/_examples/snake_game.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def GameView():
2121
return GameLoop(grid_size=6, block_scale=50, set_game_state=set_game_state)
2222

2323
start_button = idom.html.button(
24-
{"onClick": lambda event: set_game_state(GameState.play)},
25-
"Start",
24+
{"on_click": lambda event: set_game_state(GameState.play)}, "Start"
2625
)
2726

2827
if game_state == GameState.won:
@@ -40,7 +39,7 @@ def GameView():
4039
"""
4140
)
4241

43-
return idom.html.div({"className": "snake-game-menu"}, menu_style, menu)
42+
return idom.html.div({"class_name": "snake-game-menu"}, menu_style, menu)
4443

4544

4645
class Direction(enum.Enum):
@@ -72,7 +71,7 @@ def on_direction_change(event):
7271
if direction_vector_sum != (0, 0):
7372
direction.current = maybe_new_direction
7473

75-
grid_wrapper = idom.html.div({"onKeyDown": on_direction_change}, grid)
74+
grid_wrapper = idom.html.div({"on_key_down": on_direction_change}, grid)
7675

7776
assign_grid_block_color(grid, food, "blue")
7877

@@ -149,7 +148,7 @@ def create_grid(grid_size, block_scale):
149148
"grid-template-columns": f"repeat({grid_size}, {block_scale}px)",
150149
"grid-template-rows": f"repeat({grid_size}, {block_scale}px)",
151150
},
152-
"tabIndex": -1,
151+
"tab_index": -1,
153152
},
154153
[
155154
idom.html.div(
@@ -170,11 +169,11 @@ def create_grid_block(color, block_scale, key):
170169
"style": {
171170
"height": f"{block_scale}px",
172171
"width": f"{block_scale}px",
173-
"backgroundColor": color,
172+
"background_color": color,
174173
"outline": "1px solid grey",
175174
},
176175
"key": key,
177-
},
176+
}
178177
)
179178

180179

‎docs/source/reference/_examples/todo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ async def remove_task(event, index=index):
1717
set_items(items[:index] + items[index + 1 :])
1818

1919
task_text = idom.html.td(idom.html.p(text))
20-
delete_button = idom.html.td({"onClick": remove_task}, idom.html.button(["x"]))
20+
delete_button = idom.html.td({"on_click": remove_task}, idom.html.button(["x"]))
2121
tasks.append(idom.html.tr(task_text, delete_button))
2222

23-
task_input = idom.html.input({"onKeyDown": add_new_task})
23+
task_input = idom.html.input({"on_key_down": add_new_task})
2424
task_table = idom.html.table(tasks)
2525

2626
return idom.html.div(

‎docs/source/reference/_examples/use_reducer_counter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def Counter():
1717
count, dispatch = idom.hooks.use_reducer(reducer, 0)
1818
return idom.html.div(
1919
f"Count: {count}",
20-
idom.html.button({"onClick": lambda event: dispatch("reset")}, "Reset"),
21-
idom.html.button({"onClick": lambda event: dispatch("increment")}, "+"),
22-
idom.html.button({"onClick": lambda event: dispatch("decrement")}, "-"),
20+
idom.html.button({"on_click": lambda event: dispatch("reset")}, "Reset"),
21+
idom.html.button({"on_click": lambda event: dispatch("increment")}, "+"),
22+
idom.html.button({"on_click": lambda event: dispatch("decrement")}, "-"),
2323
)
2424

2525

‎docs/source/reference/_examples/use_state_counter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def Counter():
1515
count, set_count = idom.hooks.use_state(initial_count)
1616
return idom.html.div(
1717
f"Count: {count}",
18-
idom.html.button({"onClick": lambda event: set_count(initial_count)}, "Reset"),
19-
idom.html.button({"onClick": lambda event: set_count(increment)}, "+"),
20-
idom.html.button({"onClick": lambda event: set_count(decrement)}, "-"),
18+
idom.html.button({"on_click": lambda event: set_count(initial_count)}, "Reset"),
19+
idom.html.button({"on_click": lambda event: set_count(increment)}, "+"),
20+
idom.html.button({"on_click": lambda event: set_count(decrement)}, "-"),
2121
)
2222

2323

‎tests/test_backend/test_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def Counter():
5858
return idom.html.button(
5959
{
6060
"id": "counter",
61-
"onClick": lambda event: set_count(lambda old_count: old_count + 1),
61+
"on_click": lambda event: set_count(lambda old_count: old_count + 1),
6262
},
6363
f"Count: {count}",
6464
)

‎tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def ButtonWithChangingColor():
8787
return idom.html.button(
8888
{
8989
"id": "my-button",
90-
"onClick": lambda event: set_color_toggle(not color_toggle),
91-
"style": {"backgroundColor": color, "color": "white"},
90+
"on_click": lambda event: set_color_toggle(not color_toggle),
91+
"style": {"background_color": color, "color": "white"},
9292
},
9393
f"color: {color}",
9494
)
@@ -126,7 +126,7 @@ async def handle_change(event):
126126
await asyncio.sleep(delay)
127127
set_value(event["target"]["value"])
128128

129-
return idom.html.input({"onChange": handle_change, "id": "test-input"})
129+
return idom.html.input({"on_change": handle_change, "id": "test-input"})
130130

131131
await display.show(SomeComponent)
132132

‎tests/test_core/test_events.py

Lines changed: 9 additions & 11 deletions
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,7 +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(
174+
{"on_click": on_click, "id": "click"}, ["Click Me!"]
175+
)
174176
else:
175177
return idom.html.p({"id": "complete"}, ["Complete"])
176178

@@ -195,24 +197,20 @@ def outer_click_is_not_triggered(event):
195197

196198
outer = idom.html.div(
197199
{
198-
"style": {
199-
"height": "35px",
200-
"width": "35px",
201-
"backgroundColor": "red",
202-
},
203-
"onClick": outer_click_is_not_triggered,
200+
"style": {"height": "35px", "width": "35px", "background_color": "red"},
201+
"on_click": outer_click_is_not_triggered,
204202
"id": "outer",
205203
},
206204
idom.html.div(
207205
{
208206
"style": {
209207
"height": "30px",
210208
"width": "30px",
211-
"backgroundColor": "blue",
209+
"background_color": "blue",
212210
},
213-
"onClick": inner_click_no_op,
211+
"on_click": inner_click_no_op,
214212
"id": "inner",
215-
},
213+
}
216214
),
217215
)
218216
return outer

‎tests/test_core/test_hooks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ def TestComponent():
183183
idom.html.button(
184184
{
185185
"id": "r_1",
186-
"onClick": event_count_tracker(lambda event: set_state(r_1)),
186+
"on_click": event_count_tracker(lambda event: set_state(r_1)),
187187
},
188188
"r_1",
189189
),
190190
idom.html.button(
191191
{
192192
"id": "r_2",
193-
"onClick": event_count_tracker(lambda event: set_state(r_2)),
193+
"on_click": event_count_tracker(lambda event: set_state(r_2)),
194194
},
195195
"r_2",
196196
),
@@ -237,7 +237,7 @@ async def on_change(event):
237237
set_message(event["target"]["value"])
238238

239239
if message is None:
240-
return idom.html.input({"id": "input", "onChange": on_change})
240+
return idom.html.input({"id": "input", "on_change": on_change})
241241
else:
242242
return idom.html.p({"id": "complete"}, ["Complete"])
243243

@@ -267,7 +267,9 @@ def double_set_state(event):
267267
idom.html.div(
268268
{"id": "second", "data-value": state_2}, f"value is: {state_2}"
269269
),
270-
idom.html.button({"id": "button", "onClick": double_set_state}, "click me"),
270+
idom.html.button(
271+
{"id": "button", "on_click": double_set_state}, "click me"
272+
),
271273
)
272274

273275
await display.show(SomeComponent)

‎tests/test_core/test_layout.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ def bad_trigger():
506506

507507
children = [
508508
idom.html.button(
509-
{"onClick": good_trigger, "id": "good", "key": "good"}, "good"
509+
{"on_click": good_trigger, "id": "good", "key": "good"}, "good"
510510
),
511511
idom.html.button(
512-
{"onClick": bad_trigger, "id": "bad", "key": "bad"}, "bad"
512+
{"on_click": bad_trigger, "id": "bad", "key": "bad"}, "bad"
513513
),
514514
]
515515

@@ -567,7 +567,7 @@ def callback():
567567
def callback():
568568
raise ValueError("Called bad trigger")
569569

570-
return idom.html.button({"onClick": callback, "id": "good"}, "good")
570+
return idom.html.button({"on_click": callback, "id": "good"}, "good")
571571

572572
async with idom.Layout(RootComponent()) as layout:
573573
await layout.render()
@@ -649,8 +649,8 @@ def HasEventHandlerAtRoot():
649649
value, set_value = idom.hooks.use_state(False)
650650
set_value(not value) # trigger renders forever
651651
event_handler.current = weakref(set_value)
652-
button = idom.html.button({"onClick": set_value}, "state is: ", value)
653-
event_handler.current = weakref(button["eventHandlers"]["onClick"].function)
652+
button = idom.html.button({"on_click": set_value}, "state is: ", value)
653+
event_handler.current = weakref(button["eventHandlers"]["on_click"].function)
654654
return button
655655

656656
async with idom.Layout(HasEventHandlerAtRoot()) as layout:
@@ -671,8 +671,8 @@ def HasNestedEventHandler():
671671
value, set_value = idom.hooks.use_state(False)
672672
set_value(not value) # trigger renders forever
673673
event_handler.current = weakref(set_value)
674-
button = idom.html.button({"onClick": set_value}, "state is: ", value)
675-
event_handler.current = weakref(button["eventHandlers"]["onClick"].function)
674+
button = idom.html.button({"on_click": set_value}, "state is: ", value)
675+
event_handler.current = weakref(button["eventHandlers"]["on_click"].function)
676676
return idom.html.div(idom.html.div(button))
677677

678678
async with idom.Layout(HasNestedEventHandler()) as layout:
@@ -753,7 +753,7 @@ def ComponentWithBadEventHandler():
753753
def raise_error():
754754
raise Exception("bad event handler")
755755

756-
return idom.html.button({"onClick": raise_error})
756+
return idom.html.button({"on_click": raise_error})
757757

758758
with assert_idom_did_log(match_error="bad event handler"):
759759
async with idom.Layout(ComponentWithBadEventHandler()) as layout:
@@ -850,7 +850,7 @@ def SomeComponent():
850850
[
851851
idom.html.div(
852852
{"key": i},
853-
idom.html.input({"onChange": lambda event: None}),
853+
idom.html.input({"on_change": lambda event: None}),
854854
)
855855
for i in items
856856
]

‎tests/test_core/test_serve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ async def handle_event():
115115
second_event_did_execute.set()
116116

117117
return idom.html.div(
118-
idom.html.button({"onClick": block_forever}),
119-
idom.html.button({"onClick": handle_event}),
118+
idom.html.button({"on_click": block_forever}),
119+
idom.html.button({"on_click": handle_event}),
120120
)
121121

122122
send_queue = asyncio.Queue()

0 commit comments

Comments
 (0)
Please sign in to comment.