__init__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """Namespace for experimental features."""
  2. from types import SimpleNamespace
  3. from reflex.components.datadisplay.shiki_code_block import code_block as code_block
  4. from reflex.utils.console import warn
  5. from reflex.utils.misc import run_in_thread
  6. from . import hooks as hooks
  7. from .client_state import ClientStateVar as ClientStateVar
  8. class ExperimentalNamespace(SimpleNamespace):
  9. """Namespace for experimental features."""
  10. def __getattribute__(self, item: str):
  11. """Get attribute from the namespace.
  12. Args:
  13. item: attribute name.
  14. Returns:
  15. The attribute.
  16. """
  17. warn(
  18. "`rx._x` contains experimental features and might be removed at any time in the future.",
  19. dedupe=True,
  20. )
  21. return super().__getattribute__(item)
  22. @property
  23. def run_in_thread(self):
  24. """Temporary property returning the run_in_thread helper function.
  25. Remove this property when run_in_thread is fully promoted.
  26. Returns:
  27. The run_in_thread helper function.
  28. """
  29. self.register_component_warning("run_in_thread")
  30. return run_in_thread
  31. @staticmethod
  32. def register_component_warning(component_name: str):
  33. """Add component to emitted warnings and throw a warning if it
  34. doesn't exist.
  35. Args:
  36. component_name: name of the component.
  37. """
  38. warn(
  39. f"`rx._x.{component_name}` was promoted to `rx.{component_name}`.",
  40. dedupe=True,
  41. )
  42. _x = ExperimentalNamespace(
  43. client_state=ClientStateVar.create,
  44. hooks=hooks,
  45. code_block=code_block,
  46. )