ReduxStore, support for a Redux style "store of truth"

In the new ReduxStore component, state is derived from any number automatically generated surrogate stores. The surrogate stores are presented to the application for update via callbacks. When a callback completes, the updated surrogate is copied to a master store. This mechanism acts as a data multiplexor feeding application state changes from Dash UI events into an immutable single source of truth that can then be used to trigger additional activity in the UI.

from dash_redux import ReduxStore

Redux = ReduxStore(id='store', data = { "todo": []})

@Redux.update(button.input.n_clicks, input.state.value)
def new_activity(button_clicks, input, state):
    if button_clicks and input:
          state['todo'].append(input)
    return state

@Redux.action(undo.input.n_clicks)
def _undo(button_clicks):
    return action.undo if button_clicks else NOUPDATE

@Redux.action(redo.input.n_clicks)
def _redo(button_clicks):
    return action.redo if button_clicks else NOUPDATE

See dash-redux for more information.

3 Likes

Ooh this sounds awesome! Looking forward to taking this for a spin soon. :slight_smile: If I’m understanding correctly, this should make handling user preferences across the entire application much more cohesive, right? I’ve been waffling between different options to tackle that and was going to go down the path of just creating a tree-like dictionary, but this seems like it would be much easier to work with!

Woah, really intesting @jonesst2608 ! Thanks for sharing. In your experience, were you able to replace this with callbacks or was it a bit of mix and match?