Skip to content

Commit 79a9dab

Browse files
committed
Merge remote-tracking branch 'upstream/main' into react-to-preact
2 parents a8a8f4a + a64456f commit 79a9dab

23 files changed

+107
-139
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@v2
49+
uses: github/codeql-action/init@v3
5050
with:
5151
languages: ${{ matrix.language }}
5252
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -59,7 +59,7 @@ jobs:
5959
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
6060
# If this step fails, then you should remove it and run the build manually (see below)
6161
- name: Autobuild
62-
uses: github/codeql-action/autobuild@v2
62+
uses: github/codeql-action/autobuild@v3
6363

6464
# ℹ️ Command-line programs to run using the OS shell.
6565
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -72,6 +72,6 @@ jobs:
7272
# ./location_of_script_within_repo/buildscript.sh
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@v2
75+
uses: github/codeql-action/analyze@v3
7676
with:
7777
category: "/language:${{matrix.language}}"

.github/workflows/publish-develop-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
python-version: 3.x
2020
- name: Install dependencies
21-
run: pip install --upgrade pip hatch uv
21+
run: pip install hatch
2222
- name: Configure Git
2323
run: |
2424
git config user.name github-actions

.github/workflows/publish-latest-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
python-version: 3.x
2020
- name: Install dependencies
21-
run: pip install --upgrade pip hatch uv
21+
run: pip install hatch
2222
- name: Configure Git
2323
run: |
2424
git config user.name github-actions

.github/workflows/publish-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
python-version: "3.x"
1919
- name: Install dependencies
20-
run: pip install --upgrade pip hatch uv
20+
run: pip install hatch
2121
- name: Build Package
2222
run: hatch build --clean
2323
- name: Publish to PyPI

.github/workflows/test-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
python-version: 3.x
2424
- name: Install Python Dependencies
25-
run: pip install --upgrade pip hatch uv
25+
run: pip install hatch
2626
# DISABLED DUE TO DJANGO DOCS CONSTANTLY THROWING 429 ERRORS
2727
# - name: Check documentation links
2828
# run: hatch run docs:linkcheck

.github/workflows/test-javascript.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020
with:
2121
python-version: 3.x
2222
- name: Install Python Dependencies
23-
run: pip install --upgrade pip hatch uv
23+
run: pip install hatch
2424
- name: Run Tests
2525
run: hatch run javascript:check

.github/workflows/test-python.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030
- name: Install Python Dependencies
31-
run: pip install --upgrade pip hatch uv
31+
run: pip install hatch
3232
- name: Run Single DB Tests
3333
run: hatch test --python ${{ matrix.python-version }} --ds=test_app.settings_${{matrix.settings-module}} -v
3434

@@ -43,7 +43,7 @@ jobs:
4343
with:
4444
python-version: 3.x
4545
- name: Install Python Dependencies
46-
run: pip install --upgrade pip hatch uv
46+
run: pip install hatch
4747
- name: Check Python formatting
4848
run: hatch fmt src tests --check
4949

@@ -58,6 +58,6 @@ jobs:
5858
with:
5959
python-version: 3.x
6060
- name: Install Python Dependencies
61-
run: pip install --upgrade pip hatch uv
61+
run: pip install hatch
6262
- name: Run Python type checker
6363
run: hatch run python:type_check

docs/examples/python/django_router.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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
)
Lines changed: 26 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 13 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 25 additions & 25 deletions
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
)

0 commit comments

Comments
 (0)