2525    EventHandlerType ,
2626    ImportSourceDict ,
2727    JavaScript ,
28+     JSExecutableDict ,
2829    VdomAttributes ,
2930    VdomChildren ,
3031    VdomDict ,
4647                "children" : {"$ref" : "#/definitions/elementChildren" },
4748                "attributes" : {"type" : "object" },
4849                "eventHandlers" : {"$ref" : "#/definitions/elementEventHandlers" },
50+                 "jsExecutables" : {"$ref" : "#/definitions/elementJSExecutables" },
4951                "importSource" : {"$ref" : "#/definitions/importSource" },
5052            },
5153            # The 'tagName' is required because its presence is a useful indicator of 
7577            },
7678            "required" : ["target" ],
7779        },
80+         "elementJSExecutables" : {
81+             "type" : "object" ,
82+             "patternProperties" : {
83+                 ".*" : "str" ,
84+             },
85+         },
7886        "importSource" : {
7987            "type" : "object" ,
8088            "properties" : {
@@ -164,7 +172,9 @@ def __call__(
164172        """The entry point for the VDOM API, for example reactpy.html(<WE_ARE_HERE>).""" 
165173        attributes , children  =  separate_attributes_and_children (attributes_and_children )
166174        key  =  attributes .get ("key" , None )
167-         attributes , event_handlers  =  separate_attributes_and_event_handlers (attributes )
175+         attributes , event_handlers , js_executables  =  (
176+             separate_attributes_handlers_and_executables (attributes )
177+         )
168178        if  REACTPY_CHECK_JSON_ATTRS .current :
169179            json .dumps (attributes )
170180
@@ -184,6 +194,7 @@ def __call__(
184194                ** ({"children" : children } if  children  else  {}),
185195                ** ({"attributes" : attributes } if  attributes  else  {}),
186196                ** ({"eventHandlers" : event_handlers } if  event_handlers  else  {}),
197+                 ** ({"jsExecutables" : js_executables } if  js_executables  else  {}),
187198                ** ({"importSource" : self .import_source } if  self .import_source  else  {}),
188199            }
189200
@@ -216,28 +227,26 @@ def separate_attributes_and_children(
216227    return  _attributes , _children 
217228
218229
219- def  separate_attributes_and_event_handlers (
230+ def  separate_attributes_handlers_and_executables (
220231    attributes : Mapping [str , Any ],
221- ) ->  tuple [VdomAttributes , EventHandlerDict ]:
232+ ) ->  tuple [VdomAttributes , EventHandlerDict ,  JSExecutableDict ]:
222233    _attributes : VdomAttributes  =  {}
223-     _event_handlers : dict [str , EventHandlerType  |  JavaScript ] =  {}
234+     _event_handlers : dict [str , EventHandlerType ] =  {}
235+     _js_executables : dict [str , JavaScript ] =  {}
224236
225237    for  k , v  in  attributes .items ():
226-         handler : EventHandlerType  |  JavaScript 
227- 
228238        if  callable (v ):
229-             handler  =  EventHandler (to_event_handler_function (v ))
239+             _event_handlers [k ] =  EventHandler (to_event_handler_function (v ))
240+         elif  isinstance (v , EventHandler ):
241+             _event_handlers [k ] =  v 
230242        elif  EVENT_ATTRIBUTE_PATTERN .match (k ) and  isinstance (v , str ):
231-             handler  =  JavaScript (v )
232-         elif  isinstance (v , ( EventHandler ,  JavaScript ) ):
233-             handler  =  v 
243+             _js_executables [ k ]  =  JavaScript (v )
244+         elif  isinstance (v , JavaScript ):
245+             _js_executables [ k ]  =  v 
234246        else :
235247            _attributes [k ] =  v 
236-             continue 
237- 
238-         _event_handlers [k ] =  handler 
239248
240-     return  _attributes , _event_handlers 
249+     return  _attributes , _event_handlers ,  _js_executables 
241250
242251
243252def  _flatten_children (children : Sequence [Any ]) ->  list [Any ]:
0 commit comments