Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use class variables in runtime modules #642

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading