Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def register(self, custom_element_cls):
"""
Register a new custom element.
Not that there is not need to explicitly call this method. When creating a new custom element,
the element will be registered for you if it isn't already registered.
:param custom_element_cls: A subclass of ``CustomElement``.
"""
assert CustomElement._is_custom(custom_element_cls)
if custom_element_cls._registered:
return
self._register(custom_element_cls, obj_id=custom_element_cls.__name__)
custom_element_cls._registered = True
self._dispatch({'type': 'refresh'})
This method can return different results depending on ``obj`` type.
If ``obj`` is a class that inherits from Element, a new element of that type will be created.
If ``obj`` is a dict or list, it will be parsed and the parser result will be created.
If ``obj`` is a string, it will be yaml loaded and that result will be passed to the parser.
When result is passed to the parser, an additional ``inputs`` argument can be supplied as a dict from keys
to values that are referenced in the DSL using the ``$`` intrinsic function.
:param obj: The ``Element`` subclass, a dict/list or a string to be passed to the parser.
:param kwargs: Arguments that should be passed to the ``_init`` method of the created element or one of
``props``, ``style``, ``id``, ``inputs`` if valid.
:return: The created element.
"""
from . import parser
if CustomElement._is_custom(obj) and not obj._registered:
self.register(obj)
if parser.is_parsable(obj):
context = parser.ParserContext(inputs=kwargs.pop('inputs', None))
element_configuration = self._parse(obj, context)
return self._new_children(element_configuration, **kwargs)
else:
return self._new_child(obj, **kwargs)