Skip to content

Commit 5d7dbdd

Browse files
committed
Adds test for string_to_reactpy
1 parent 4920d95 commit 5d7dbdd

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/reactpy/core/vdom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
VdomJson,
3333
)
3434

35-
EVENT_ATTRIBUTE_PATTERN = re.compile(r"^on[A-Z]")
35+
EVENT_ATTRIBUTE_PATTERN = re.compile(r"^on\w+")
3636

3737
VDOM_JSON_SCHEMA = {
3838
"$schema": "http://json-schema.org/draft-07/schema",

src/reactpy/types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ class VdomTypeDict(TypedDict):
790790
children: NotRequired[Sequence[ComponentType | VdomChild]]
791791
attributes: NotRequired[VdomAttributes]
792792
eventHandlers: NotRequired[EventHandlerDict]
793-
jsExecutables: NotRequired[JavaScript]
793+
jsExecutables: NotRequired[JSExecutableDict]
794794
importSource: NotRequired[ImportSourceDict]
795795

796796

@@ -896,6 +896,7 @@ class JsonImportSource(TypedDict):
896896

897897

898898
class JavaScript(str):
899+
"""A simple way of marking JavaScript code to be executed client-side"""
899900
pass
900901

901902

@@ -937,7 +938,7 @@ class EventHandlerType(Protocol):
937938
"""A dict mapping between event names to their handlers"""
938939

939940
JSExecutableMapping = Mapping[str, JavaScript]
940-
"""A generic mapping between event names to their javascript"""
941+
"""A generic mapping between attribute names to their javascript"""
941942

942943
JSExecutableDict: TypeAlias = dict[str, JavaScript]
943944
"""A dict mapping between attribute names to their javascript"""

tests/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ def test_string_to_reactpy(case):
194194
"key": "my-key",
195195
},
196196
},
197+
# 9: Includes `jsExecutables` attribue
198+
{
199+
"source": '''<button onclick="this.innerText = 'CLICKED'">Click Me</button>''',
200+
"model": {
201+
"tagName": "button",
202+
"jsExecutables": {"onclick": "this.innerText = 'CLICKED'"},
203+
"children": ["Click Me"],
204+
}
205+
},
197206
],
198207
)
199208
def test_string_to_reactpy_default_transforms(case):

0 commit comments

Comments
 (0)