Skip to content

Commit fb84879

Browse files
committed
ReactPy V2 changes
1 parent 169e33e commit fb84879

File tree

65 files changed

+2173
-2728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2173
-2728
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from reactpy import component, html
2+
3+
4+
@component
5+
def hello_world():
6+
return html.div("Hello World")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from jinja2 import Environment, FileSystemLoader
2+
from starlette.applications import Starlette
3+
from starlette.routing import Route
4+
from starlette.templating import Jinja2Templates
5+
6+
from reactpy.templatetags import ReactPyJinja
7+
8+
jinja_templates = Jinja2Templates(
9+
env=Environment(
10+
loader=FileSystemLoader("path/to/my_templates"),
11+
extensions=[ReactPyJinja],
12+
)
13+
)
14+
15+
16+
async def example_webpage(request):
17+
return jinja_templates.TemplateResponse(request, "my_template.html")
18+
19+
20+
starlette_app = Starlette(routes=[Route("/", example_webpage)])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from jinja2 import Environment, FileSystemLoader
2+
from starlette.applications import Starlette
3+
from starlette.routing import Route
4+
from starlette.templating import Jinja2Templates
5+
6+
from reactpy.executors.asgi import ReactPyMiddleware
7+
from reactpy.templatetags import ReactPyJinja
8+
9+
jinja_templates = Jinja2Templates(
10+
env=Environment(
11+
loader=FileSystemLoader("path/to/my_templates"),
12+
extensions=[ReactPyJinja],
13+
)
14+
)
15+
16+
17+
async def example_webpage(request):
18+
return jinja_templates.TemplateResponse(request, "my_template.html")
19+
20+
21+
starlette_app = Starlette(routes=[Route("/", example_webpage)])
22+
reactpy_app = ReactPyMiddleware(starlette_app, ["my_components.hello_world"])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>ReactPy in Django</title>
6+
</head>
7+
8+
<body>
9+
{% component "my_components.hello_world" %}
10+
</body>
11+
12+
</html>

Diff for: docs/examples/creating_a_react_app/asgi_csr.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pathlib import Path
2+
3+
from reactpy.executors.asgi import ReactPyCsr
4+
5+
my_app = ReactPyCsr(
6+
Path(__file__).parent / "components" / "root.py", initial="Loading..."
7+
)

Diff for: docs/examples/creating_a_react_app/asgi_csr_root.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from reactpy import component, html
2+
3+
4+
@component
5+
def root():
6+
return html.div("Hello World")

Diff for: docs/examples/creating_a_react_app/asgi_ssr.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from reactpy import component, html
2+
from reactpy.executors.asgi import ReactPy
3+
4+
5+
@component
6+
def hello_world():
7+
return html.div("Hello World")
8+
9+
10+
my_app = ReactPy(hello_world)

Diff for: docs/examples/python/quick_start/adding_styles.py

-4
This file was deleted.

Diff for: docs/examples/python/responding_to_events/simple_button_event.py

-22
This file was deleted.

Diff for: docs/examples/python/start_a_new_react_project/configure_example.py

-6
This file was deleted.

Diff for: docs/examples/python/thinking_in_react/set_state_props.py

-32
This file was deleted.

Diff for: docs/examples/quick_start/adding_styles.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from reactpy import html
2+
3+
# start
4+
html.img({"className": "avatar"})

Diff for: docs/examples/python/quick_start/creating_and_nesting_components.py renamed to docs/examples/quick_start/creating_and_nesting_components.py

-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,3 @@ def my_app():
1212
html.h1("Welcome to my app"),
1313
my_button(),
1414
)
15-
16-
17-
# end
18-
if __name__ == "__main__":
19-
from reactpy import run
20-
21-
run(my_app)

Diff for: docs/examples/python/quick_start/displaying_data.py renamed to docs/examples/quick_start/displaying_data.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def profile():
1313
html.h3(user["name"]),
1414
html.img(
1515
{
16-
"class_name": "avatar",
16+
"className": "avatar",
1717
"src": user["image_url"],
1818
"alt": f"Photo of {user['name']}",
1919
"style": {
@@ -23,15 +23,3 @@ def profile():
2323
}
2424
),
2525
)
26-
27-
28-
# end
29-
if __name__ == "__main__":
30-
from reactpy import run
31-
from reactpy.utils import _read_docs_css
32-
33-
@component
34-
def styled_app():
35-
return html._(html.style(_read_docs_css()), profile())
36-
37-
run(styled_app)
File renamed without changes.

Diff for: docs/examples/python/quick_start/rendering_lists.py renamed to docs/examples/quick_start/rendering_lists.py

-7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,3 @@ def shopping_list():
2121
]
2222

2323
return html.ul(list_items)
24-
25-
26-
# end
27-
if __name__ == "__main__":
28-
from reactpy import run
29-
30-
run(shopping_list)

Diff for: docs/examples/python/quick_start/responding_to_events.py renamed to docs/examples/quick_start/responding_to_events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def handle_click(event):
88
print("You clicked me!")
99

1010
return html.button(
11-
{"on_click": handle_click},
11+
{"onClick": handle_click},
1212
"Click me",
1313
)

Diff for: docs/examples/python/quick_start/sharing_data_between_components.py renamed to docs/examples/quick_start/sharing_data_between_components.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,4 @@ def handle_click(event):
1717

1818
@component
1919
def my_button(count, on_click):
20-
return html.button({"on_click": on_click}, f"Clicked {count} times")
21-
22-
23-
# end
24-
if __name__ == "__main__":
25-
from reactpy import run
26-
from reactpy.utils import _read_docs_css
27-
28-
@component
29-
def styled_app():
30-
return html._(html.style(_read_docs_css()), my_app())
31-
32-
run(styled_app)
20+
return html.button({"onClick": on_click}, f"Clicked {count} times")

Diff for: docs/examples/python/quick_start/sharing_data_between_components_button.py renamed to docs/examples/quick_start/sharing_data_between_components_button.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# start
55
@component
66
def my_button(count, on_click):
7-
return html.button({"on_click": on_click}, f"Clicked {count} times")
7+
return html.button({"onClick": on_click}, f"Clicked {count} times")

Diff for: docs/examples/python/quick_start/updating_the_screen.py renamed to docs/examples/quick_start/updating_the_screen.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,4 @@ def my_button():
1717
def handle_click(event):
1818
set_count(count + 1)
1919

20-
return html.button({"on_click": handle_click}, f"Clicked {count} times")
21-
22-
23-
# end
24-
if __name__ == "__main__":
25-
from reactpy import run
26-
from reactpy.utils import _read_docs_css
27-
28-
@component
29-
def styled_app():
30-
return html._(html.style(_read_docs_css()), my_app())
31-
32-
run(styled_app)
20+
return html.button({"onClick": handle_click}, f"Clicked {count} times")

Diff for: docs/examples/python/quick_start/updating_the_screen_event.py renamed to docs/examples/quick_start/updating_the_screen_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ def my_button():
99
def handle_click(event):
1010
set_count(count + 1)
1111

12-
return html.button({"on_click": handle_click}, f"Clicked {count} times")
12+
return html.button({"onClick": handle_click}, f"Clicked {count} times")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from reactpy import component, html
2+
3+
4+
@component
5+
def button():
6+
def handle_click(event):
7+
print("You clicked me!")
8+
9+
return html.button({"onClick": handle_click}, "Click me")

Diff for: docs/examples/python/thinking_in_react/add_inverse_data_flow.py renamed to docs/examples/thinking_in_react/add_inverse_data_flow.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ def search_bar(filter_text, in_stock_only, set_filter_text, set_in_stock_only):
7575
"type": "text",
7676
"value": filter_text,
7777
"placeholder": "Search...",
78-
"on_change": lambda event: set_filter_text(event["target"]["value"]),
78+
"onChange": lambda event: set_filter_text(event["target"]["value"]),
7979
}
8080
),
8181
html.label(
8282
html.input(
8383
{
8484
"type": "checkbox",
8585
"checked": in_stock_only,
86-
"on_change": lambda event: set_in_stock_only(
86+
"onChange": lambda event: set_in_stock_only(
8787
event["target"]["checked"]
8888
),
8989
}
@@ -106,15 +106,3 @@ def search_bar(filter_text, in_stock_only, set_filter_text, set_in_stock_only):
106106
@component
107107
def app():
108108
return filterable_product_table(PRODUCTS)
109-
110-
111-
# end
112-
if __name__ == "__main__":
113-
from reactpy import run
114-
from reactpy.utils import _read_docs_css
115-
116-
@component
117-
def styled_app():
118-
return html._(html.style(_read_docs_css()), app())
119-
120-
run(styled_app)

Diff for: docs/examples/python/thinking_in_react/build_a_static_version_in_react.py renamed to docs/examples/thinking_in_react/build_a_static_version_in_react.py

-12
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,3 @@ def filterable_product_table(products):
5858
@component
5959
def app():
6060
return filterable_product_table(PRODUCTS)
61-
62-
63-
# end
64-
if __name__ == "__main__":
65-
from reactpy import run
66-
from reactpy.utils import _read_docs_css
67-
68-
@component
69-
def styled_app():
70-
return html._(html.style(_read_docs_css()), app())
71-
72-
run(styled_app)

Diff for: docs/examples/python/thinking_in_react/event_handlers.py renamed to docs/examples/thinking_in_react/event_handlers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
filter_text = ""
44

55

6-
def set_filter_text(value):
7-
...
6+
def set_filter_text(value): ...
87

98

109
# start
@@ -13,6 +12,6 @@ def set_filter_text(value):
1312
"type": "text",
1413
"value": filter_text,
1514
"placeholder": "Search...",
16-
"on_change": lambda event: set_filter_text(event["target"]["value"]),
15+
"onChange": lambda event: set_filter_text(event["target"]["value"]),
1716
}
1817
)

Diff for: docs/examples/python/thinking_in_react/identify_where_your_state_should_live.py renamed to docs/examples/thinking_in_react/identify_where_your_state_should_live.py

-12
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,3 @@ def search_bar(filter_text, in_stock_only):
8686
@component
8787
def app():
8888
return filterable_product_table(PRODUCTS)
89-
90-
91-
# end
92-
if __name__ == "__main__":
93-
from reactpy import run
94-
from reactpy.utils import _read_docs_css
95-
96-
@component
97-
def styled_app():
98-
return html._(html.style(_read_docs_css()), app())
99-
100-
run(styled_app)

Diff for: docs/examples/thinking_in_react/set_state_props.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from reactpy import component, hooks, html
2+
3+
4+
def search_bar(**_kws): ...
5+
6+
7+
# start
8+
@component
9+
def filterable_product_table(products):
10+
filter_text, set_filter_text = hooks.use_state("")
11+
in_stock_only, set_in_stock_only = hooks.use_state(False)
12+
13+
return html.div(
14+
search_bar(
15+
filter_text=filter_text,
16+
in_stock_only=in_stock_only,
17+
set_filter_text=set_filter_text,
18+
set_in_stock_only=set_in_stock_only,
19+
)
20+
)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from reactpy import component, html
22

3+
34
# start
45
@component
56
def square():
6-
return html.button({"class_name":"square"}, "X")
7+
return html.button({"className": "square"}, "X")

0 commit comments

Comments
 (0)