Skip to content

Commit f0ff025

Browse files
authored
revert #841 (#919)
* revert 764a5a8 - but preserve ability to declare attributes with snake_case - move 'key' to be an attribute rather than keyword argument in constructor + make auto converter for this change based on the one used for the "new" `*args` and `**kwargs` syntax we are reverting. * add key rewrite script * changelog * fix types * apply rewrites * add custom vdom constructor decorator * change to snake * fix err msg * cast keys to strings * make pub * fix dashed html attrs * rename to rewrite-keys * fix types * allow ints in vdom spec for keys * fix types * camelCase to snake_case + rewrite util * fix types * get cov * fix style
1 parent d415bcf commit f0ff025

File tree

90 files changed

+1266
-1266
lines changed

Some content is hidden

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

90 files changed

+1266
-1266
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
repos:
22
- repo: https://github.com/ambv/black
3-
rev: 22.6.0
3+
rev: 23.1.0
44
hooks:
55
- id: black
66
- repo: https://github.com/pycqa/isort
7-
rev: 5.6.3
7+
rev: 5.12.0
88
hooks:
99
- id: isort
1010
name: isort
1111
- repo: https://github.com/pre-commit/mirrors-prettier
12-
rev: "v2.5.1"
12+
rev: v2.7.1
1313
hooks:
1414
- id: prettier

docs/examples.py

+1-1
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(text, class_name="printout") 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/_custom_js/package-lock.json

+13-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/_exts/custom_autosectionlabel.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from fnmatch import fnmatch
8-
from typing import Any, cast
8+
from typing import Any, Dict, cast
99

1010
from docutils import nodes
1111
from docutils.nodes import Node
@@ -30,6 +30,7 @@ def get_node_depth(node: Node) -> int:
3030

3131
def register_sections_as_label(app: Sphinx, document: Node) -> None:
3232
docname = app.env.docname
33+
print(docname)
3334

3435
for pattern in app.config.autosectionlabel_skip_docs:
3536
if fnmatch(docname, pattern):
@@ -66,7 +67,7 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
6667
domain.labels[name] = docname, labelid, sectname
6768

6869

69-
def setup(app: Sphinx) -> dict[str, Any]:
70+
def setup(app: Sphinx) -> Dict[str, Any]:
7071
app.add_config_value("autosectionlabel_prefix_document", False, "env")
7172
app.add_config_value("autosectionlabel_maxdepth", None, "env")
7273
app.add_config_value("autosectionlabel_skip_docs", [], "env")

docs/source/about/changelog.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
2323
Unreleased
2424
----------
2525

26-
No changes.
26+
**Changed**
27+
28+
- :pull:`919` - Reverts :pull:`841` as per the conclusion in :discussion:`916`. but
29+
preserves the ability to declare attributes with snake_case.
30+
31+
**Deprecated**
32+
33+
- :pull:`919` - Declaration of keys via keywork arguments in standard elements. A script
34+
has been added to automatically convert old usages where possible.
2735

2836

2937
v1.0.0-a3

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def handle_click(event):
2525
url = sculpture["url"]
2626

2727
return html.div(
28-
html.button("Next", on_click=handle_click),
28+
html.button({"on_click": handle_click}, "Next"),
2929
html.h2(name, " by ", artist),
3030
html.p(f"({bounded_index + 1} of {len(sculpture_data)})"),
31-
html.img(src=url, alt=alt, style={"height": "200px"}),
31+
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
3232
html.p(description),
3333
)
3434

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def handle_more_click(event):
2929
url = sculpture["url"]
3030

3131
return html.div(
32-
html.button("Next", on_click=handle_next_click),
32+
html.button({"on_click": handle_next_click}, "Next"),
3333
html.h2(name, " by ", artist),
3434
html.p(f"({bounded_index + 1} or {len(sculpture_data)})"),
35-
html.img(src=url, alt=alt, style={"height": "200px"}),
35+
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
3636
html.div(
3737
html.button(
38+
{"on_click": handle_more_click},
3839
f"{('Show' if show_more else 'Hide')} details",
39-
on_click=handle_more_click,
4040
),
4141
(html.p(description) if show_more else ""),
4242
),
@@ -46,8 +46,8 @@ def handle_more_click(event):
4646
@component
4747
def App():
4848
return html.div(
49-
html.section(Gallery(), style={"width": "50%", "float": "left"}),
50-
html.section(Gallery(), style={"width": "50%", "float": "left"}),
49+
html.section({"style": {"width": "50%", "float": "left"}}, Gallery()),
50+
html.section({"style": {"width": "50%", "float": "left"}}, Gallery()),
5151
)
5252

5353

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def handle_more_click(event):
2929
url = sculpture["url"]
3030

3131
return html.div(
32-
html.button("Next", on_click=handle_next_click),
32+
html.button({"on_click": handle_next_click}, "Next"),
3333
html.h2(name, " by ", artist),
3434
html.p(f"({bounded_index + 1} or {len(sculpture_data)})"),
35-
html.img(src=url, alt=alt, style={"height": "200px"}),
35+
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
3636
html.div(
3737
html.button(
38+
{"on_click": handle_more_click},
3839
f"{('Show' if show_more else 'Hide')} details",
39-
on_click=handle_more_click,
4040
),
4141
(html.p(description) if show_more else ""),
4242
),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def handle_click(event):
3131
url = sculpture["url"]
3232

3333
return html.div(
34-
html.button("Next", on_click=handle_click),
34+
html.button({"on_click": handle_click}, "Next"),
3535
html.h2(name, " by ", artist),
3636
html.p(f"({bounded_index + 1} or {len(sculpture_data)})"),
37-
html.img(src=url, alt=alt, style={"height": "200px"}),
37+
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
3838
html.p(description),
3939
)
4040

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,29 @@ def handle_click(event):
2626
return handle_click
2727

2828
return html.div(
29-
html.button("add term", on_click=handle_add_click),
29+
html.button({"on_click": handle_add_click}, "add term"),
3030
html.label(
3131
"Term: ",
32-
html.input(value=term_to_add, on_change=handle_term_to_add_change),
32+
html.input({"value": term_to_add, "on_change": handle_term_to_add_change}),
3333
),
3434
html.label(
3535
"Definition: ",
3636
html.input(
37-
value=definition_to_add, on_change=handle_definition_to_add_change
37+
{
38+
"value": definition_to_add,
39+
"on_change": handle_definition_to_add_change,
40+
}
3841
),
3942
),
4043
html.hr(),
4144
[
4245
html.div(
43-
html.button("delete term", on_click=make_delete_click_handler(term)),
46+
{"key": term},
47+
html.button(
48+
{"on_click": make_delete_click_handler(term)}, "delete term"
49+
),
4450
html.dt(term),
4551
html.dd(definition),
46-
key=term,
4752
)
4853
for term, definition in all_terms.items()
4954
],

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ def handle_email_change(event):
2323
return html.div(
2424
html.label(
2525
"First name: ",
26-
html.input(value=person["first_name"], on_change=handle_first_name_change),
26+
html.input(
27+
{"value": person["first_name"], "on_change": handle_first_name_change}
28+
),
2729
),
2830
html.label(
2931
"Last name: ",
30-
html.input(value=person["last_name"], on_change=handle_last_name_change),
32+
html.input(
33+
{"value": person["last_name"], "on_change": handle_last_name_change}
34+
),
3135
),
3236
html.label(
3337
"Email: ",
34-
html.input(value=person["email"], on_change=handle_email_change),
38+
html.input({"value": person["email"], "on_change": handle_email_change}),
3539
),
3640
html.p(f"{person['first_name']} {person['last_name']} {person['email']}"),
3741
)

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def handle_click(event):
1616

1717
return html.div(
1818
html.h1("Inspiring sculptors:"),
19-
html.input(value=artist_to_add, on_change=handle_change),
20-
html.button("add", on_click=handle_click),
21-
html.ul([html.li(name, key=name) for name in artists]),
19+
html.input({"value": artist_to_add, "on_change": handle_change}),
20+
html.button({"on_click": handle_click}, "add"),
21+
html.ul([html.li({"key": name}, name) for name in artists]),
2222
)
2323

2424

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def handle_reverse_click(event):
1515

1616
return html.div(
1717
html.h1("Inspiring sculptors:"),
18-
html.button("sort", on_click=handle_sort_click),
19-
html.button("reverse", on_click=handle_reverse_click),
20-
html.ul([html.li(name, key=name) for name in artists]),
18+
html.button({"on_click": handle_sort_click}, "sort"),
19+
html.button({"on_click": handle_reverse_click}, "reverse"),
20+
html.ul([html.li({"key": name}, name) for name in artists]),
2121
)
2222

2323

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ def handle_click(event):
2424

2525
return html.div(
2626
html.h1("Inspiring sculptors:"),
27-
html.input(value=artist_to_add, on_change=handle_change),
28-
html.button("add", on_click=handle_add_click),
27+
html.input({"value": artist_to_add, "on_change": handle_change}),
28+
html.button({"on_click": handle_add_click}, "add"),
2929
html.ul(
3030
[
3131
html.li(
32+
{"key": name},
3233
name,
33-
html.button("delete", on_click=make_handle_delete_click(index)),
34-
key=name,
34+
html.button(
35+
{"on_click": make_handle_delete_click(index)}, "delete"
36+
),
3537
)
3638
for index, name in enumerate(artists)
3739
]

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def handle_click(event):
1515
return html.ul(
1616
[
1717
html.li(
18+
{"key": index},
1819
count,
19-
html.button("+1", on_click=make_increment_click_handler(index)),
20-
key=index,
20+
html.button({"on_click": make_increment_click_handler(index)}, "+1"),
2121
)
2222
for index, count in enumerate(counters)
2323
]

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ async def handle_pointer_move(event):
1616
)
1717

1818
return html.div(
19+
{
20+
"on_pointer_move": handle_pointer_move,
21+
"style": {
22+
"position": "relative",
23+
"height": "200px",
24+
"width": "100%",
25+
"backgroundColor": "white",
26+
},
27+
},
1928
html.div(
20-
style={
21-
"position": "absolute",
22-
"background_color": "red",
23-
"border_radius": "50%",
24-
"width": "20px",
25-
"height": "20px",
26-
"left": "-10px",
27-
"top": "-10px",
28-
"transform": f"translate({position['x']}px, {position['y']}px)",
29+
{
30+
"style": {
31+
"position": "absolute",
32+
"backgroundColor": "red",
33+
"borderRadius": "50%",
34+
"width": "20px",
35+
"height": "20px",
36+
"left": "-10px",
37+
"top": "-10px",
38+
"transform": f"translate({position['x']}px, {position['y']}px)",
39+
}
2940
}
3041
),
31-
on_pointer_move=handle_pointer_move,
32-
style={
33-
"position": "relative",
34-
"height": "200px",
35-
"width": "100%",
36-
"background_color": "white",
37-
},
3842
)
3943

4044

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@ def handle_pointer_move(event):
1414
position["y"] = event["clientY"] - outer_div_bounds["y"]
1515

1616
return html.div(
17+
{
18+
"on_pointer_move": handle_pointer_move,
19+
"style": {
20+
"position": "relative",
21+
"height": "200px",
22+
"width": "100%",
23+
"backgroundColor": "white",
24+
},
25+
},
1726
html.div(
18-
style={
19-
"position": "absolute",
20-
"background_color": "red",
21-
"border_radius": "50%",
22-
"width": "20px",
23-
"height": "20px",
24-
"left": "-10px",
25-
"top": "-10px",
26-
"transform": f"translate({position['x']}px, {position['y']}px)",
27+
{
28+
"style": {
29+
"position": "absolute",
30+
"backgroundColor": "red",
31+
"borderRadius": "50%",
32+
"width": "20px",
33+
"height": "20px",
34+
"left": "-10px",
35+
"top": "-10px",
36+
"transform": f"translate({position['x']}px, {position['y']}px)",
37+
}
2738
}
2839
),
29-
on_pointer_move=handle_pointer_move,
30-
style={
31-
"position": "relative",
32-
"height": "200px",
33-
"width": "100%",
34-
"background_color": "white",
35-
},
3640
)
3741

3842

0 commit comments

Comments
 (0)