MCPcopy Index your code
hub / github.com/reactive-python/reactpy / make_vdom_constructor

Function make_vdom_constructor

src/py/reactpy/reactpy/core/vdom.py:213–244  ·  view source on GitHub ↗

Return a constructor for VDOM dictionaries with the given tag name. The resulting callable will have the same interface as :func:`vdom` but without its first ``tag`` argument.

(
    tag: str, allow_children: bool = True, import_source: ImportSourceDict | None = None
)

Source from the content-addressed store, hash-verified

211
212
213def make_vdom_constructor(
214 tag: str, allow_children: bool = True, import_source: ImportSourceDict | None = None
215) -> VdomDictConstructor:
216 """Return a constructor for VDOM dictionaries with the given tag name.
217
218 The resulting callable will have the same interface as :func:`vdom` but without its
219 first ``tag`` argument.
220 """
221
222 def constructor(*attributes_and_children: Any, **kwargs: Any) -> VdomDict:
223 model = vdom(tag, *attributes_and_children, **kwargs)
224 if not allow_children and "children" in model:
225 msg = f"{tag!r} nodes cannot have children."
226 raise TypeError(msg)
227 if import_source:
228 model["importSource"] = import_source
229 return model
230
231 # replicate common function attributes
232 constructor.__name__ = tag
233 constructor.__doc__ = (
234 "Return a new "
235 f"`<{tag}> <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/{tag}>`__ "
236 "element represented by a :class:`VdomDict`."
237 )
238
239 module_name = f_module_name(1)
240 if module_name:
241 constructor.__module__ = module_name
242 constructor.__qualname__ = f"{module_name}.{tag}"
243
244 return cast(VdomDictConstructor, constructor)
245
246
247def custom_vdom_constructor(func: _CustomVdomDictConstructor) -> VdomDictConstructor:

Callers 4

html.pyFile · 0.90
svg.pyFile · 0.90
_make_exportFunction · 0.90

Calls 1

f_module_nameFunction · 0.90

Tested by 1