sda.dashboard.state#

State Management Package.


Consolidated state management for the SDA Dashboard.

Submodules#

Classes#

DashboardState

Centralized dashboard state management.

StateDefinition

Definition of a state variable.

StateManager

High-level state management interface.

StateScope

Scope of state storage.

Functions#

get_state_manager([verbose])

Get the global state manager instance.

Package Contents#

class sda.dashboard.state.DashboardState(verbose=False)#

Centralized dashboard state management.

verbose = False#
define_state(definition)#

Define a new state variable.

Parameters:

definition (StateDefinition) – State variable definition

create_stores(initial_values=None)#

Create Dash Store components for all defined state.

Parameters:

initial_values (Dict[str, Any], optional) – Initial values to set in stores

Returns:

List of Store components to add to layout

Return type:

List[dcc.Store]

get_store_id(state_key)#

Get the store ID for a state key.

Parameters:

state_key (str) – State key name

Returns:

Dash Store component ID

Return type:

str

validate_state(state_key, value)#

Validate a state value.

Parameters:
  • state_key (str) – State key name

  • value (Any) – Value to validate

Returns:

Whether the value is valid

Return type:

bool

get_dependencies(state_key)#

Get dependencies for a state variable.

Parameters:

state_key (str) – State key name

Returns:

List of dependency state keys

Return type:

List[str]

add_watcher(state_key, callback)#

Add a watcher function for state changes.

Parameters:
  • state_key (str) – State key to watch

  • callback (callable) – Function to call when state changes

class sda.dashboard.state.StateDefinition#

Definition of a state variable.

key: str#
default_value: Any = None#
scope: StateScope#
description: str = ''#
validation_fn: Callable | None = None#
dependencies: List[str] = []#
class sda.dashboard.state.StateManager(dashboard_state, verbose=False)#

High-level state management interface.

state#
verbose = False#
batch_update(updates)#

Batch multiple state updates.

Parameters:

updates (Dict[str, Any]) – Dictionary of state_key: new_value pairs

Returns:

List of validation errors, if any

Return type:

List[str]

get_update_queue()#

Get and clear the update queue.

Returns:

Queued updates

Return type:

List[Dict[str, Any]]

create_consolidated_layout()#

Create consolidated state layout component.

Returns:

Div containing all state stores

Return type:

html.Div

class sda.dashboard.state.StateScope(*args, **kwds)#

Bases: enum.Enum

Scope of state storage.

SESSION = 'session'#
LOCAL = 'local'#
MEMORY = 'memory'#
sda.dashboard.state.get_state_manager(verbose=False)#

Get the global state manager instance.

Parameters:

verbose (bool) – Whether to enable verbose logging

Returns:

Global state manager instance

Return type:

StateManager