File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
client/packages/idom-client-react/src Expand file tree Collapse file tree 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 }) {
3434 } else {
3535 return null ;
3636 }
37+ } else if ( model . tagName == "script" ) {
38+ return html `< ${ ScriptElement } script =${ model . children [ 0 ] } /> ` ;
3739 } else if ( model . importSource ) {
3840 return html `< ${ ImportedElement } model =${ model } /> ` ;
3941 } else {
@@ -56,6 +58,12 @@ function StandardElement({ model }) {
5658 ) ;
5759}
5860
61+ function ScriptElement ( { script } ) {
62+ const el = React . useRef ( ) ;
63+ React . useEffect ( eval ( script ) , [ script ] ) ;
64+ return null ;
65+ }
66+
5967function ImportedElement ( { model } ) {
6068 const layoutContext = React . useContext ( LayoutContext ) ;
6169
Original file line number Diff line number Diff line change 150150- :func:`template`
151151"""
152152
153- from .core .vdom import make_vdom_constructor
153+ from .core .vdom import VdomDict , make_vdom_constructor
154154
155155
156156# Dcument metadata
253253del_ = make_vdom_constructor ("del" )
254254ins = make_vdom_constructor ("ins" )
255255
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+
256272# Table content
257273caption = make_vdom_constructor ("caption" )
258274col = make_vdom_constructor ("col" )
You can’t perform that action at this time.
0 commit comments