MCPcopy Create free account
hub / github.com/dot-agent/nextpy / modify_state

Method modify_state

nextpy/app.py:807–833  ·  view source on GitHub ↗

Modify the state out of band. Args: token: The token to modify the state for. Yields: The state to modify. Raises: RuntimeError: If the app has not been initialized yet.

(self, token: str)

Source from the content-addressed store, hash-verified

805 compiler_utils.write_page(output_path, code)
806 @contextlib.asynccontextmanager
807 async def modify_state(self, token: str) -> AsyncIterator[BaseState]:
808 """Modify the state out of band.
809
810 Args:
811 token: The token to modify the state for.
812
813 Yields:
814 The state to modify.
815
816 Raises:
817 RuntimeError: If the app has not been initialized yet.
818 """
819 if self.event_namespace is None:
820 raise RuntimeError("App has not been initialized yet.")
821
822 # Get exclusive access to the state.
823 async with self.state_manager.modify_state(token) as state:
824 # No other event handler can modify the state while in this context.
825 yield state
826 delta = state.get_delta()
827 if delta:
828 # When the state is modified reset dirty status and emit the delta to the frontend.
829 state._clean()
830 await self.event_namespace.emit_update(
831 update=StateUpdate(delta=delta),
832 sid=state.router.session.session_id,
833 )
834
835 def _process_background(
836 self, state: BaseState, event: Event

Callers 10

test_client_side_stateFunction · 0.45
processFunction · 0.45
_ndjson_updatesFunction · 0.45
_coroFunction · 0.45
_coro_blockerFunction · 0.45
_coro_waiterFunction · 0.45

Calls 4

StateUpdateClass · 0.90
get_deltaMethod · 0.80
_cleanMethod · 0.80
emit_updateMethod · 0.80

Tested by 8

test_client_side_stateFunction · 0.36
_coroFunction · 0.36
_coro_blockerFunction · 0.36
_coro_waiterFunction · 0.36