Skip to content

Commit a64456f

Browse files
authored
Fix docs typos (#289)
1 parent b19bed8 commit a64456f

13 files changed

+79
-61
lines changed

docs/examples/python/django_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def my_component():
1515
route("/router/string/<str:value>/", html.div("Example 6")),
1616
route("/router/uuid/<uuid:value>/", html.div("Example 7")),
1717
route("/router/two_values/<int:value>/<str:value2>/", html.div("Example 8")),
18-
route("/router/*", html.div("Fallback")),
18+
route("/router/<any:value>", html.div("Fallback")),
1919
)

docs/examples/python/use_mutation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ def submit_event(event):
2525

2626
return html.div(
2727
html.label("Add an item:"),
28-
html.input({"type": "text", "on_key_down": submit_event}),
28+
html.input({"type": "text", "onKeyDown": submit_event}),
2929
mutation_status,
3030
)

docs/examples/python/use_mutation_query_refetch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def submit_event(event):
3939

4040
return html.div(
4141
html.label("Add an item:"),
42-
html.input({"type": "text", "on_key_down": submit_event}),
42+
html.input({"type": "text", "onKeyDown": submit_event}),
4343
mutation_status,
4444
rendered_items,
4545
)

docs/examples/python/use_mutation_reset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def submit_event(event):
2222
if item_mutation.loading:
2323
mutation_status = html.h2("Adding...")
2424
elif item_mutation.error:
25-
mutation_status = html.button({"on_click": reset_event}, "Error: Try again!")
25+
mutation_status = html.button({"onClick": reset_event}, "Error: Try again!")
2626
else:
2727
mutation_status = html.h2("Mutation done.")
2828

2929
return html.div(
3030
html.label("Add an item:"),
31-
html.input({"type": "text", "on_key_down": submit_event}),
31+
html.input({"type": "text", "onKeyDown": submit_event}),
3232
mutation_status,
3333
)

docs/examples/python/use_mutation_thread_sensitive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def submit_event(event):
2626
mutation_status = html.h2("Done.")
2727

2828
return html.div(
29-
html.input({"type": "text", "on_key_down": submit_event}),
29+
html.input({"type": "text", "onKeyDown": submit_event}),
3030
mutation_status,
3131
)
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from channels.db import database_sync_to_async
2+
from reactpy import component, html
3+
4+
from example.models import TodoItem
5+
from reactpy_django.hooks import use_query
6+
7+
8+
async def get_items():
9+
return await database_sync_to_async(TodoItem.objects.all)()
10+
11+
12+
@component
13+
def todo_list():
14+
item_query = use_query(get_items)
15+
16+
if item_query.loading:
17+
rendered_items = html.h2("Loading...")
18+
elif item_query.error or not item_query.data:
19+
rendered_items = html.h2("Error when loading!")
20+
else:
21+
rendered_items = html.ul([html.li(item.text, key=item.pk) for item in item_query.data])
22+
23+
def on_click(event):
24+
item_query.refetch()
25+
26+
return html.div("Rendered items: ", rendered_items, html.button({"onClick": on_click}, "Refresh"))

docs/examples/python/use_user_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def on_submit(event):
1616
html.div(f"Data: {query.data}"),
1717
html.div(f"Loading: {query.loading | mutation.loading}"),
1818
html.div(f"Error(s): {query.error} {mutation.error}"),
19-
html.input({"on_key_press": on_submit}),
19+
html.input({"onKeyPress": on_submit}),
2020
)

docs/src/reference/hooks.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,16 @@ Query functions can be sync or async.
135135

136136
{% include-markdown "../../includes/orm.md" start="<!--orm-excp-start-->" end="<!--orm-excp-end-->" %}
137137

138-
??? question "Can I make a failed query try again?"
138+
??? question "Can I force a query to run again?"
139139

140-
Yes, `#!python use_mutation` can be re-executed by calling `#!python reset()` on your `#!python use_mutation` instance.
140+
`#!python use_query` can be re-executed by calling `#!python refetch()` on your `#!python use_query` result.
141141

142-
For example, take a look at `#!python reset_event` below.
142+
The example below uses an `#!python onClick` event to determine when to reset the query.
143143

144144
=== "components.py"
145145

146146
```python
147-
{% include "../../examples/python/use_mutation_reset.py" %}
148-
```
149-
150-
=== "models.py"
151-
152-
```python
153-
{% include "../../examples/python/todo_item_model.py" %}
147+
{% include "../../examples/python/use_query_refetch.py" %}
154148
```
155149

156150
??? question "Why does the example query function return `#!python TodoItem.objects.all()`?"
@@ -231,9 +225,9 @@ Mutation functions can be sync or async.
231225

232226
{% include-markdown "../../includes/orm.md" start="<!--orm-excp-start-->" end="<!--orm-excp-end-->" %}
233227

234-
??? question "Can I make a failed mutation try again?"
228+
??? question "Can I force a mutation run again?"
235229

236-
Yes, `#!python use_mutation` can be re-executed by calling `#!python reset()` on your `#!python use_mutation` instance.
230+
`#!python use_mutation` can be re-executed by calling `#!python reset()` on your `#!python use_mutation` result.
237231

238232
For example, take a look at `#!python reset_event` below.
239233

@@ -251,7 +245,7 @@ Mutation functions can be sync or async.
251245

252246
??? question "Can `#!python use_mutation` trigger a refetch of `#!python use_query`?"
253247

254-
Yes, `#!python use_mutation` can queue a refetch of a `#!python use_query` via the `#!python refetch=...` argument.
248+
`#!python use_mutation` can queue a refetch of a `#!python use_query` via the `#!python refetch=...` argument.
255249

256250
The example below is a merge of the `#!python use_query` and `#!python use_mutation` examples above with the addition of a `#!python use_mutation(refetch=...)` argument.
257251

docs/src/reference/router.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ URL router that enables the ability to conditionally render other components bas
2525
You can duplicate all your URL patterns within both Django and ReactPy, but it's easiest to use a wildcard `.*` within Django's `#!python urlpatterns` and let ReactPy handle the rest. For example...
2626

2727
```python linenums="0"
28-
urlpatterns = [
29-
re_path(r"^.*$", my_reactpy_router_view),
30-
]
28+
urlpatterns = [ re_path(r"^.*$", my_reactpy_router_view) ]
3129
```
3230

3331
=== "components.py"

tests/test_app/components.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def button():
3838
html.div(
3939
"button:",
4040
html.button(
41-
{"id": "counter-inc", "on_click": lambda _: set_count(count + 1)},
41+
{"id": "counter-inc", "onClick": lambda _: set_count(count + 1)},
4242
"Click me!",
4343
),
4444
html.p({"id": "counter-num", "data-count": count}, f"Current count is: {count}"),
@@ -293,7 +293,7 @@ def _render_todo_items(items, toggle_item):
293293
"id": f"todo-item-{item.text}-checkbox",
294294
"type": "checkbox",
295295
"checked": item.done,
296-
"on_change": lambda _, i=item: toggle_item(i),
296+
"onChange": lambda _, i=item: toggle_item(i),
297297
}),
298298
)
299299
for item in items
@@ -342,8 +342,8 @@ def on_change(event):
342342
"type": "text",
343343
"id": "todo-input",
344344
"value": input_value,
345-
"on_key_press": on_submit,
346-
"on_change": on_change,
345+
"onKeyPress": on_submit,
346+
"onChange": on_change,
347347
}),
348348
mutation_status,
349349
rendered_items,
@@ -413,8 +413,8 @@ async def on_change(event):
413413
"type": "text",
414414
"id": "async-todo-input",
415415
"value": input_value,
416-
"on_key_press": on_submit,
417-
"on_change": on_change,
416+
"onKeyPress": on_submit,
417+
"onChange": on_change,
418418
}),
419419
mutation_status,
420420
rendered_items,
@@ -508,7 +508,7 @@ def on_click(_):
508508
html.button(
509509
{
510510
"id": f"{inspect.currentframe().f_code.co_name}_btn",
511-
"on_click": on_click,
511+
"onClick": on_click,
512512
},
513513
"Click me",
514514
),
@@ -527,7 +527,7 @@ def on_click(_):
527527
html.button(
528528
{
529529
"id": f"{inspect.currentframe().f_code.co_name}_btn",
530-
"on_click": on_click,
530+
"onClick": on_click,
531531
},
532532
"Click me",
533533
),
@@ -546,7 +546,7 @@ def on_click(_):
546546
html.button(
547547
{
548548
"id": f"{inspect.currentframe().f_code.co_name}_btn",
549-
"on_click": on_click,
549+
"onClick": on_click,
550550
},
551551
"Click me",
552552
),
@@ -561,7 +561,7 @@ def custom_host(number=0):
561561

562562
return html.div(
563563
{
564-
"class_name": f"{inspect.currentframe().f_code.co_name}-{number}",
564+
"className": f"{inspect.currentframe().f_code.co_name}-{number}",
565565
"data-port": port,
566566
},
567567
f"Server Port: {port}",
@@ -630,15 +630,15 @@ async def on_submit(event):
630630
"data-username": ("AnonymousUser" if current_user.is_anonymous else current_user.username),
631631
},
632632
html.div("use_user_data"),
633-
html.button({"className": "login-1", "on_click": login_user1}, "Login 1"),
634-
html.button({"className": "login-2", "on_click": login_user2}, "Login 2"),
635-
html.button({"className": "logout", "on_click": logout_user}, "Logout"),
636-
html.button({"className": "clear", "on_click": clear_data}, "Clear Data"),
633+
html.button({"className": "login-1", "onClick": login_user1}, "Login 1"),
634+
html.button({"className": "login-2", "onClick": login_user2}, "Login 2"),
635+
html.button({"className": "logout", "onClick": logout_user}, "Logout"),
636+
html.button({"className": "clear", "onClick": clear_data}, "Clear Data"),
637637
html.div(f"User: {current_user}"),
638638
html.div(f"Data: {user_data_query.data}"),
639639
html.div(f"Data State: (loading={user_data_query.loading}, error={user_data_query.error})"),
640640
html.div(f"Mutation State: (loading={user_data_mutation.loading}, error={user_data_mutation.error})"),
641-
html.div(html.input({"on_key_press": on_submit, "placeholder": "Type here to add data"})),
641+
html.div(html.input({"onKeyPress": on_submit, "placeholder": "Type here to add data"})),
642642
)
643643

644644

@@ -685,13 +685,13 @@ async def on_submit(event):
685685
"data-username": ("AnonymousUser" if current_user.is_anonymous else current_user.username),
686686
},
687687
html.div("use_user_data_with_default"),
688-
html.button({"className": "login-3", "on_click": login_user3}, "Login 3"),
689-
html.button({"className": "clear", "on_click": clear_data}, "Clear Data"),
688+
html.button({"className": "login-3", "onClick": login_user3}, "Login 3"),
689+
html.button({"className": "clear", "onClick": clear_data}, "Clear Data"),
690690
html.div(f"User: {current_user}"),
691691
html.div(f"Data: {user_data_query.data}"),
692692
html.div(f"Data State: (loading={user_data_query.loading}, error={user_data_query.error})"),
693693
html.div(f"Mutation State: (loading={user_data_mutation.loading}, error={user_data_mutation.error})"),
694-
html.div(html.input({"on_key_press": on_submit, "placeholder": "Type here to add data"})),
694+
html.div(html.input({"onKeyPress": on_submit, "placeholder": "Type here to add data"})),
695695
)
696696

697697

@@ -720,9 +720,9 @@ async def disconnect(event):
720720
},
721721
html.div("use_auth"),
722722
html.div(f"UUID: {uuid}"),
723-
html.button({"className": "login", "on_click": login_user}, "Login"),
724-
html.button({"className": "logout", "on_click": logout_user}, "Logout"),
725-
html.button({"className": "disconnect", "on_click": disconnect}, "disconnect"),
723+
html.button({"className": "login", "onClick": login_user}, "Login"),
724+
html.button({"className": "logout", "onClick": logout_user}, "Logout"),
725+
html.button({"className": "disconnect", "onClick": disconnect}, "disconnect"),
726726
html.div(f"User: {current_user}"),
727727
)
728728

@@ -752,9 +752,9 @@ async def disconnect(event):
752752
},
753753
html.div("use_auth_no_rerender"),
754754
html.div(f"UUID: {uuid}"),
755-
html.button({"className": "login", "on_click": login_user}, "Login"),
756-
html.button({"className": "logout", "on_click": logout_user}, "Logout"),
757-
html.button({"className": "disconnect", "on_click": disconnect}, "disconnect"),
755+
html.button({"className": "login", "onClick": login_user}, "Login"),
756+
html.button({"className": "logout", "onClick": logout_user}, "Logout"),
757+
html.button({"className": "disconnect", "onClick": disconnect}, "disconnect"),
758758
html.div(f"User: {current_user}"),
759759
)
760760

@@ -774,5 +774,5 @@ def on_click(event):
774774
},
775775
html.div("use_rerender"),
776776
html.div(f"UUID: {uuid}"),
777-
html.button({"on_click": on_click}, "Rerender"),
777+
html.button({"onClick": on_click}, "Rerender"),
778778
)

tests/test_app/performance/components.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ def run_tests():
1717
return html.div(
1818
html.div(f"Total renders: {count}"),
1919
html.div(
20-
{"class_name": "rps", "data-rps": rps},
20+
{"className": "rps", "data-rps": rps},
2121
f"Renders Per Second: {rps}",
2222
),
2323
)
2424

2525

2626
@component
2727
def time_to_load():
28-
return html.div({"class_name": "ttl"}, "Loaded!")
28+
return html.div({"className": "ttl"}, "Loaded!")
2929

3030

3131
GIANT_STR_10MB = "@" * 10000000
@@ -34,7 +34,7 @@ def time_to_load():
3434
@component
3535
def net_io_time_to_load():
3636
return html.div(
37-
{"class_name": "ttl"},
37+
{"className": "ttl"},
3838
html.div({"style": {"display": "none"}}, GIANT_STR_10MB),
3939
html.div("Loaded!"),
4040
)
@@ -59,7 +59,7 @@ def run_tests():
5959
html.div({"style": {"display": "none"}}, GIANT_STR_1MB),
6060
html.div(f"Total renders: {count}"),
6161
html.div(
62-
{"class_name": "rps", "data-rps": rps},
62+
{"className": "rps", "data-rps": rps},
6363
f"Renders Per Second: {rps}",
6464
),
6565
)
@@ -79,14 +79,14 @@ async def event_handler(event):
7979
return html.div(
8080
html.div(f"Total events: {count}"),
8181
html.div(
82-
{"class_name": "erps", "data-erps": erps},
82+
{"className": "erps", "data-erps": erps},
8383
f"Event Renders Per Second: {erps}",
8484
),
8585
html.input({
8686
"type": "text",
87-
"default_value": "0",
87+
"defaultValue": "0",
8888
"data-count": str(count),
89-
"on_click": event_handler,
89+
"onClick": event_handler,
9090
}),
9191
)
9292

@@ -101,12 +101,12 @@ async def event_handler(_event):
101101
return html.div(
102102
html.input(
103103
{
104-
"class_name": "et",
104+
"className": "et",
105105
"data-clicked": clicked,
106106
"data-worker-num": worker_num,
107107
"value": f"Clicked: {clicked}",
108108
"type": "button",
109-
"on_click": event_handler,
109+
"onClick": event_handler,
110110
},
111111
),
112112
)

tests/test_app/pyscript/components/child.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def root():
1010
html.div(
1111
{"className": "grid"},
1212
html.button(
13-
{"className": "plus", "on_click": lambda _: set_value(value + 1)},
13+
{"className": "plus", "onClick": lambda _: set_value(value + 1)},
1414
"+",
1515
),
1616
html.button(
17-
{"className": "minus", "on_click": lambda _: set_value(value - 1)},
17+
{"className": "minus", "onClick": lambda _: set_value(value - 1)},
1818
"-",
1919
),
2020
),

tests/test_app/pyscript/components/counter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def root():
99
html.div(
1010
{"className": "grid"},
1111
html.button(
12-
{"className": "plus", "on_click": lambda _: set_value(value + 1)},
12+
{"className": "plus", "onClick": lambda _: set_value(value + 1)},
1313
"+",
1414
),
1515
html.button(
16-
{"className": "minus", "on_click": lambda _: set_value(value - 1)},
16+
{"className": "minus", "onClick": lambda _: set_value(value - 1)},
1717
"-",
1818
),
1919
),

0 commit comments

Comments
 (0)