Skip to content

Commit e9c6f3c

Browse files
authored
update docs + changelog + fix warning (#891)
1 parent 764a5a8 commit e9c6f3c

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

docs/source/_custom_js/package-lock.json

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

docs/source/about/changelog.rst

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

26-
No changes.
26+
**Changed**
27+
28+
- :pull:`841` - Revamped element constructor interface. Now instead of passing a
29+
dictionary of attributes to element constructors, attributes are declared using
30+
keyword arguments. For example, instead of writing:
31+
32+
.. code-block::
33+
34+
html.div({"className": "some-class"}, "some", "text")
35+
36+
You now should write:
37+
38+
.. code-block::
39+
40+
html.div("some", "text", class_name="some-class")
41+
42+
.. note::
43+
44+
All attributes are written using ``snake_case``.
45+
46+
In conjunction, with these changes, IDOM now supplies a command line utility that
47+
makes a "best effort" attempt to automatically convert code to the new API. Usage of
48+
this utility is as follows:
49+
50+
.. code-block:: bash
51+
52+
idom update-html-usages [PATHS]
53+
54+
Where ``[PATHS]`` is any number of directories or files that should be rewritten.
55+
56+
.. warning::
57+
58+
After running this utility, code comments and formatting may have been altered. It's
59+
recommended that you run a code formatting tool like `Black
60+
<https://github.com/psf/black>`__ and manually review and replace any comments that
61+
may have been moved.
62+
63+
**Fixed**
64+
65+
- :issue:`755` - unification of component and VDOM constructor interfaces. See above.
2766

2867

2968
v0.44.0

docs/source/guides/creating-interfaces/html-with-idom/index.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Adding HTML Attributes
7171
----------------------
7272

7373
That's all well and good, but there's more to HTML than just text. What if we wanted to
74-
display an image? In HTMl we'd use the `<img/>` element and add attributes to it order
74+
display an image? In HTMl we'd use the ``<img>`` element and add attributes to it order
7575
to specify a URL to its ``src`` and use some ``style`` to modify and position it:
7676

7777
.. code-block:: html
@@ -80,23 +80,27 @@ to specify a URL to its ``src`` and use some ``style`` to modify and position it
8080
src="https://picsum.photos/id/237/500/300"
8181
style="width: 50%; margin-left: 25%;"
8282
alt="Billie Holiday"
83+
tabindex="0"
8384
/>
8485

85-
In IDOM we add these attributes to elements using dictionaries. There are some notable
86-
differences though. The biggest being the fact that all names in IDOM use ``camelCase``
87-
instead of dash-separated words. For example, ``margin-left`` becomes ``marginLeft``.
88-
Additionally, instead of specifying ``style`` using a string, we use a dictionary:
86+
In IDOM we add these attributes to elements using keyword arguments. There are two main
87+
notable differences though. First, all names in IDOM use ``snake_case`` instead of
88+
dash-separated words. For example, ``tabindex`` and ``margin-left`` become ``tab_index``
89+
and ``margin_left`` respectively. Second, instead of specifying ``style`` using a
90+
string, we use a dictionary. Given this, you can rewrite the ``<img>`` element above as:
8991

9092
.. testcode::
9193

9294
html.img(
9395
src="https://picsum.photos/id/237/500/300",
94-
style={"width": "50%", "marginLeft": "25%"},
96+
style={"width": "50%", "margin_left": "25%"},
9597
alt="Billie Holiday",
98+
tab_index="0",
9699
)
97100

98101
.. raw:: html
99102

103+
<!-- no tabindex since that would ruin accesibility of the page -->
100104
<img
101105
src="https://picsum.photos/id/237/500/300"
102106
style="width: 50%; margin-left: 25%;"

src/idom/backend/sanic.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ async def single_page_app_files(
119119
) -> response.HTTPResponse:
120120
return response.html(index_html)
121121

122-
spa_blueprint.add_route(single_page_app_files, "/")
123-
spa_blueprint.add_route(single_page_app_files, "/<_:path>")
122+
spa_blueprint.add_route(
123+
single_page_app_files,
124+
"/",
125+
name="single_page_app_files_root",
126+
)
127+
spa_blueprint.add_route(
128+
single_page_app_files,
129+
"/<_:path>",
130+
name="single_page_app_files_path",
131+
)
124132

125133
async def asset_files(
126134
request: request.Request,
@@ -185,8 +193,16 @@ async def model_stream(
185193
recv,
186194
)
187195

188-
api_blueprint.add_websocket_route(model_stream, f"/{STREAM_PATH.name}")
189-
api_blueprint.add_websocket_route(model_stream, f"/{STREAM_PATH.name}/<path:path>/")
196+
api_blueprint.add_websocket_route(
197+
model_stream,
198+
f"/{STREAM_PATH.name}",
199+
name="model_stream_root",
200+
)
201+
api_blueprint.add_websocket_route(
202+
model_stream,
203+
f"/{STREAM_PATH.name}/<path:path>/",
204+
name="model_stream_path",
205+
)
190206

191207

192208
def _make_send_recv_callbacks(

0 commit comments

Comments
 (0)