Modify some methods in state.py to prevent being overwritten (#856)
This commit is contained in:
parent
54b06fb5a8
commit
73cfd2fdba
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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"},
|
||||
|
Loading…
Reference in New Issue
Block a user