Skip to content

Commit

Permalink
Do not use class variables in runtime modules (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen authored Jul 19, 2024
1 parent 30305ce commit afa304b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
23 changes: 8 additions & 15 deletions mesop/runtime/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@


class Context:
_states: dict[type[Any], object]
# Previous states is used for performing state diffs.
_previous_states: dict[type[Any], object]
_handlers: dict[str, Handler]
_commands: list[pb.Command]
_node_slot: pb.Component | None
_node_slot_children_count: int | None
_viewport_size: pb.ViewportSize | None = None

def __init__(
self,
get_handler: Callable[[str], Handler | None],
Expand All @@ -36,13 +27,15 @@ def __init__(
self._get_handler = get_handler
self._current_node = pb.Component()
self._previous_node: pb.Component | None = None
self._states = states
self._previous_states = copy.deepcopy(states)
self._states: dict[type[Any], object] = states
# Previous states is used for performing state diffs.
self._previous_states: dict[type[Any], object] = copy.deepcopy(states)
self._trace_mode = False
self._handlers = {}
self._commands = []
self._node_slot = None
self._node_slot_children_count = None
self._handlers: dict[str, Handler] = {}
self._commands: list[pb.Command] = []
self._node_slot: pb.Component | None = None
self._node_slot_children_count: int | None = None
self._viewport_size: pb.ViewportSize | None = None

def commands(self) -> list[pb.Command]:
return self._commands
Expand Down
31 changes: 13 additions & 18 deletions mesop/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,21 @@ class PageConfig:


class Runtime:
_path_to_page_config: dict[str, PageConfig] = {}
_handlers: dict[str, Handler]
_state_classes: list[type[Any]]
_loading_errors: list[pb.ServerError]
component_fns: set[Callable[..., Any]]
js_modules: set[str] = set()
debug_mode: bool = False
# If True, then the server is still re-executing the modules
# needed for hot reloading.
is_hot_reload_in_progress: bool = False
# Keeps track of the hot reload count so that the server can tell
# clients polling whether to request a hot reload.
hot_reload_counter = 0

def __init__(self):
self.component_fns = set()
self._handlers = {}
self.debug_mode: bool = False
# If True, then the server is still re-executing the modules
# needed for hot reloading.
self.is_hot_reload_in_progress: bool = False
# Keeps track of the hot reload count so that the server can tell
# clients polling whether to request a hot reload.
self.hot_reload_counter = 0
self._path_to_page_config: dict[str, PageConfig] = {}
self.component_fns: set[Callable[..., Any]] = set()
self.js_modules: set[str] = set()
self._handlers: dict[str, Handler] = {}
self.event_mappers: dict[Type[Any], Callable[[pb.UserEvent, Key], Any]] = {}
self._state_classes = []
self._loading_errors = []
self._state_classes: list[type[Any]] = []
self._loading_errors: list[pb.ServerError] = []

def context(self) -> Context:
if "_mesop_context" not in g:
Expand Down

0 comments on commit afa304b

Please sign in to comment.