Skip to content

Commit f180c45

Browse files
committed
Hand the docs examples coroutine event handlers
Every example which bound a callback wrote it as a lambda, and a lambda cannot be awaited. They are named coroutines now, which is also the shape the guides tell people to write.
1 parent 586b29e commit f180c45

36 files changed

Lines changed: 160 additions & 87 deletions

File tree

‎docs/source/guides/adding-interactivity/components-with-state/_examples/adding_state_variable/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def Gallery():
1313
index, set_index = hooks.use_state(0)
1414

15-
def handle_click(event):
15+
async def handle_click(event):
1616
set_index(index + 1)
1717

1818
bounded_index = index % len(sculpture_data)

‎docs/source/guides/adding-interactivity/components-with-state/_examples/isolated_state/main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def Gallery():
1313
index, set_index = hooks.use_state(0)
1414
show_more, set_show_more = hooks.use_state(False)
1515

16-
def handle_next_click(event):
16+
async def handle_next_click(event):
1717
set_index(index + 1)
1818

19-
def handle_more_click(event):
19+
async def handle_more_click(event):
2020
set_show_more(not show_more)
2121

2222
bounded_index = index % len(sculpture_data)

‎docs/source/guides/adding-interactivity/components-with-state/_examples/multiple_state_variables/main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def Gallery():
1313
index, set_index = hooks.use_state(0)
1414
show_more, set_show_more = hooks.use_state(False)
1515

16-
def handle_next_click(event):
16+
async def handle_next_click(event):
1717
set_index(index + 1)
1818

19-
def handle_more_click(event):
19+
async def handle_more_click(event):
2020
set_show_more(not show_more)
2121

2222
bounded_index = index % len(sculpture_data)

‎docs/source/guides/adding-interactivity/components-with-state/_examples/when_variables_are_not_enough/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def Gallery():
2020
index = 0
2121

22-
def handle_click(event):
22+
async def handle_click(event):
2323
index = index + 1
2424

2525
bounded_index = index % len(sculpture_data)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ def Definitions():
77
definition_to_add, set_definition_to_add = use_state(None)
88
all_terms, set_all_terms = use_state({})
99

10-
def handle_term_to_add_change(event):
10+
async def handle_term_to_add_change(event):
1111
set_term_to_add(event["target"]["value"])
1212

13-
def handle_definition_to_add_change(event):
13+
async def handle_definition_to_add_change(event):
1414
set_definition_to_add(event["target"]["value"])
1515

16-
def handle_add_click(event):
16+
async def handle_add_click(event):
1717
if term_to_add and definition_to_add:
1818
set_all_terms({**all_terms, term_to_add: definition_to_add})
1919
set_term_to_add(None)
2020
set_definition_to_add(None)
2121

22-
def make_delete_click_handler(term_to_delete):
23-
def handle_click(event):
22+
async def make_delete_click_handler(term_to_delete):
23+
async def handle_click(event):
2424
set_all_terms({t: d for t, d in all_terms.items() if t != term_to_delete})
2525

2626
return handle_click

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ def Form():
1111
}
1212
)
1313

14-
def handle_first_name_change(event):
14+
async def handle_first_name_change(event):
1515
set_person({**person, "first_name": event["target"]["value"]})
1616

17-
def handle_last_name_change(event):
17+
async def handle_last_name_change(event):
1818
set_person({**person, "last_name": event["target"]["value"]})
1919

20-
def handle_email_change(event):
20+
async def handle_email_change(event):
2121
set_person({**person, "email": event["target"]["value"]})
2222

2323
return html.div(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ def ArtistList():
66
artist_to_add, set_artist_to_add = use_state("")
77
artists, set_artists = use_state([])
88

9-
def handle_change(event):
9+
async def handle_change(event):
1010
set_artist_to_add(event["target"]["value"])
1111

12-
def handle_click(event):
12+
async def handle_click(event):
1313
if artist_to_add and artist_to_add not in artists:
1414
set_artists([*artists, artist_to_add])
1515
set_artist_to_add("")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ def ArtistList():
77
["Marta Colvin Andrade", "Lamidi Olonade Fakeye", "Louise Nevelson"]
88
)
99

10-
def handle_sort_click(event):
10+
async def handle_sort_click(event):
1111
set_artists(sorted(artists))
1212

13-
def handle_reverse_click(event):
13+
async def handle_reverse_click(event):
1414
set_artists(list(reversed(artists)))
1515

1616
return html.div(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ def ArtistList():
88
["Marta Colvin Andrade", "Lamidi Olonade Fakeye", "Louise Nevelson"]
99
)
1010

11-
def handle_change(event):
11+
async def handle_change(event):
1212
set_artist_to_add(event["target"]["value"])
1313

14-
def handle_add_click(event):
14+
async def handle_add_click(event):
1515
if artist_to_add not in artists:
1616
set_artists([*artists, artist_to_add])
1717
set_artist_to_add("")
1818

19-
def make_handle_delete_click(index):
20-
def handle_click(event):
19+
async def make_handle_delete_click(index):
20+
async def handle_click(event):
2121
set_artists(artists[:index] + artists[index + 1 :])
2222

2323
return handle_click

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
def CounterList():
66
counters, set_counters = use_state([0, 0, 0])
77

8-
def make_increment_click_handler(index):
9-
def handle_click(event):
8+
async def make_increment_click_handler(index):
9+
async def handle_click(event):
1010
new_value = counters[index] + 1
1111
set_counters([*counters[:index], new_value, *counters[index + 1 :]])
1212

0 commit comments

Comments
 (0)