Skip to content

Commit 113611e

Browse files
committed
Convert private staticmethod to standalone method
1 parent 59bb9f5 commit 113611e

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/reactpy/transforms.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
from reactpy.types import VdomAttributes, VdomDict
77

88

9+
def attributes_to_reactjs(attributes: VdomAttributes):
10+
"""Convert HTML attribute names to their ReactJS equivalents."""
11+
attrs = cast(VdomAttributes, attributes.items())
12+
attrs = cast(
13+
VdomAttributes,
14+
{REACT_PROP_SUBSTITUTIONS.get(k, k): v for k, v in attrs},
15+
)
16+
return attrs
17+
18+
919
class RequiredTransforms:
1020
"""Performs any necessary transformations related to `string_to_reactpy` to automatically prevent
1121
issues with React's rendering engine.
@@ -36,21 +46,6 @@ def normalize_style_attributes(self, vdom: dict[str, Any]) -> None:
3646
)
3747
}
3848

39-
@staticmethod
40-
def _attributes_to_reactjs(attributes: VdomAttributes):
41-
"""Convert HTML attribute names to their ReactJS equivalents.
42-
43-
This method is private because it is called prior to instantiating a
44-
Vdom class from a parsed html string, so it does not need to be called
45-
as part of this class's instantiation (see comments in __init__ above).
46-
"""
47-
attrs = cast(VdomAttributes, attributes.items())
48-
attrs = cast(
49-
VdomAttributes,
50-
{REACT_PROP_SUBSTITUTIONS.get(k, k): v for k, v in attrs},
51-
)
52-
return attrs
53-
5449
@staticmethod
5550
def textarea_children_to_prop(vdom: VdomDict) -> None:
5651
"""Transformation that converts the text content of a <textarea> to a ReactJS prop."""

src/reactpy/utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from lxml.html import fromstring
1111

1212
from reactpy import html
13-
from reactpy.transforms import RequiredTransforms
13+
from reactpy.transforms import RequiredTransforms, attributes_to_reactjs
1414
from reactpy.types import ComponentType, VdomDict
1515

1616
_RefValue = TypeVar("_RefValue")
@@ -147,7 +147,10 @@ def _etree_to_vdom(
147147

148148
# Recursively call _etree_to_vdom() on all children
149149
children = _generate_vdom_children(node, transforms, intercept_links)
150-
attributes = RequiredTransforms._attributes_to_reactjs(dict(node.items()))
150+
151+
# This transform is required prior to initializing the Vdom so InlineJavaScript
152+
# gets properly parsed (ex. <button onClick="this.innerText = 'Clicked';")
153+
attributes = attributes_to_reactjs(dict(node.items()))
151154

152155
# Convert the lxml node to a VDOM dict
153156
constructor = getattr(html, str(node.tag))

0 commit comments

Comments
 (0)