File tree 2 files changed +25
-1
lines changed
client/packages/idom-client-react/src
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ export function Element({ model }) {
34
34
} else {
35
35
return null ;
36
36
}
37
+ } else if ( model . tagName == "script" ) {
38
+ return html `< ${ ScriptElement } script =${ model . children [ 0 ] } /> ` ;
37
39
} else if ( model . importSource ) {
38
40
return html `< ${ ImportedElement } model =${ model } /> ` ;
39
41
} else {
@@ -56,6 +58,12 @@ function StandardElement({ model }) {
56
58
) ;
57
59
}
58
60
61
+ function ScriptElement ( { script } ) {
62
+ const el = React . useRef ( ) ;
63
+ React . useEffect ( eval ( script ) , [ script ] ) ;
64
+ return null ;
65
+ }
66
+
59
67
function ImportedElement ( { model } ) {
60
68
const layoutContext = React . useContext ( LayoutContext ) ;
61
69
Original file line number Diff line number Diff line change 150
150
- :func:`template`
151
151
"""
152
152
153
- from .core .vdom import make_vdom_constructor
153
+ from .core .vdom import VdomDict , make_vdom_constructor
154
154
155
155
156
156
# Dcument metadata
253
253
del_ = make_vdom_constructor ("del" )
254
254
ins = make_vdom_constructor ("ins" )
255
255
256
+ # Scripting
257
+
258
+
259
+ def script (content : str ) -> VdomDict :
260
+ """Create a new `<{script}> <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script>`__ element.
261
+
262
+ Parameters:
263
+ content: The text of the script should evaluate to a function. This function
264
+ will be called when the script is initially created or when the content of the
265
+ script changes. The function may optionally return a teardown function that is
266
+ called when the script element is removed from the tree, or when the script
267
+ content changes.
268
+ """
269
+ return {"tagName" : "script" , "children" : [content ]}
270
+
271
+
256
272
# Table content
257
273
caption = make_vdom_constructor ("caption" )
258
274
col = make_vdom_constructor ("col" )
You can’t perform that action at this time.
0 commit comments