1
0

props.py 769 B

12345678910111213141516171819202122232425
  1. """A class that holds props to be passed or applied to a component."""
  2. from __future__ import annotations
  3. from reflex.base import Base
  4. from reflex.ivars.object import LiteralObjectVar
  5. from reflex.utils import format
  6. class PropsBase(Base):
  7. """Base for a class containing props that can be serialized as a JS object."""
  8. def json(self) -> str:
  9. """Convert the object to a json-like string.
  10. Vars will be unwrapped so they can represent actual JS var names and functions.
  11. Keys will be converted to camelCase.
  12. Returns:
  13. The object as a Javascript Object literal.
  14. """
  15. return LiteralObjectVar.create(
  16. {format.to_camel_case(key): value for key, value in self.dict().items()}
  17. ).json()