diff --git a/pynecone/app.py b/pynecone/app.py index 9a455f3c1..67b86ee94 100644 --- a/pynecone/app.py +++ b/pynecone/app.py @@ -455,7 +455,7 @@ async def process( # Apply the event to the state. if updates is None: - updates = [await state.process(event)] + updates = [await state._process(event)] app.state_manager.set_state(event.token, state) # Postprocess the event. @@ -534,7 +534,7 @@ def upload(app: App): name=handler, payload={handler_upload_param[0]: files}, ) - update = await state.process(event) + update = await state._process(event) return update return upload_file diff --git a/pynecone/middleware/hydrate_middleware.py b/pynecone/middleware/hydrate_middleware.py index 159d06e8b..ea93035a1 100644 --- a/pynecone/middleware/hydrate_middleware.py +++ b/pynecone/middleware/hydrate_middleware.py @@ -76,6 +76,6 @@ class HydrateMiddleware(Middleware): "The value of state cannot be None when processing an on-load event." ) - return await state.process_event( + return await state._process_event( handler=load_event, state=ex_state, payload=payload, token=token ) diff --git a/pynecone/state.py b/pynecone/state.py index 5a20ccb3c..a0b3c379d 100644 --- a/pynecone/state.py +++ b/pynecone/state.py @@ -575,7 +575,7 @@ class State(Base, ABC): raise ValueError(f"Invalid path: {path}") return self.substates[path[0]].get_substate(path[1:]) - async def process(self, event: Event) -> StateUpdate: + async def _process(self, event: Event) -> StateUpdate: """Obtain event info and process event. Args: @@ -598,14 +598,14 @@ class State(Base, ABC): "The value of state cannot be None when processing an event." ) - return await self.process_event( + return await self._process_event( handler=handler, state=substate, payload=event.payload, token=event.token, ) - async def process_event( + async def _process_event( self, handler: EventHandler, state: State, payload: Dict, token: str ) -> StateUpdate: """Process event. diff --git a/tests/test_app.py b/tests/test_app.py index d57f20eff..34fc070e2 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -272,7 +272,7 @@ async def test_list_mutation_detection__plain_list( list_mutation_state: A state with list mutation features. """ for event_name, expected_delta in event_tuples: - result = await list_mutation_state.process( + result = await list_mutation_state._process( Event( token="fake-token", name=event_name, @@ -399,7 +399,7 @@ async def test_dict_mutation_detection__plain_list( dict_mutation_state: A state with dict mutation features. """ for event_name, expected_delta in event_tuples: - result = await dict_mutation_state.process( + result = await dict_mutation_state._process( Event( token="fake-token", name=event_name, diff --git a/tests/test_state.py b/tests/test_state.py index fb146e17e..28f1519ae 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -576,7 +576,7 @@ async def test_process_event_simple(test_state): assert test_state.num1 == 0 event = Event(token="t", name="set_num1", payload={"value": 69}) - update = await test_state.process(event) + update = await test_state._process(event) # The event should update the value. assert test_state.num1 == 69 @@ -601,7 +601,7 @@ async def test_process_event_substate(test_state, child_state, grandchild_state) event = Event( token="t", name="child_state.change_both", payload={"value": "hi", "count": 12} ) - update = await test_state.process(event) + update = await test_state._process(event) assert child_state.value == "HI" assert child_state.count == 24 assert update.delta == { @@ -616,7 +616,7 @@ async def test_process_event_substate(test_state, child_state, grandchild_state) name="child_state.grandchild_state.set_value2", payload={"value": "new"}, ) - update = await test_state.process(event) + update = await test_state._process(event) assert grandchild_state.value2 == "new" assert update.delta == { "test_state.child_state.grandchild_state": {"value2": "new"},