How CascadeUI Thinks¶
Two pictures carry most of CascadeUI: the path one click takes from your callback to the edit on screen, and the shape of the state the store keeps. This page draws both, then maps views, sessions, and navigation to the pages that cover them.
The Data Flow¶
This is what happens when Kael clicks +1 on the counter from Adding Shared State:
- The click arrives. The library starts the timer that acknowledges the click if the callback is slow, checks that Kael may click (Who Can Click), and takes the view's turn, so clicks on it run one at a time.
- The callback dispatches.
dispatch_scoped()builds aSCOPED_UPDATEaction and hands it to the store. - Middleware sees it first, each one in the order it was installed, and passes it on (Middleware).
- The reducer works on a copy of the state and returns the new state, and the store keeps it. Reducers run one at a time (Store, Actions, and Reducers).
- The views that listen are told. A view that lists the action redraws:
on_state_changed()callsbuild_ui(), thenrefresh(). A view with a selector redraws only when what its selector returns has changed (Subscribers and Slots). - The edits go out. The clicked view's refresh answers the click and edits its message in one request. Every other view that redraws does so on a task of its own and edits its own message, so a slow one never holds up the click (Responding to Clicks).
When the callback returns, the library records a click on a StatefulButton or StatefulSelect that leaves
the view open as a COMPONENT_INTERACTION action, which takes the
same path.
A callback can also change the view's own attributes and call refresh(), as Your First Panel
does. That redraws the panel that was clicked and no other: only an action reaches the rest.
The State Tree¶
store.state is one dict with six keys. Your data lives under application, and the library keeps the other five,
and reading them helps when you debug.
| Key | One entry for | What an entry holds | After a restart |
|---|---|---|---|
views |
each live view, by its id | id, type, user_id, guild_id, session_id, message_id, channel_id, props, created_at, updated_at, plus undo_stack and redo_stack once a view with undo records a step |
empty |
sessions |
each session, by its id | id, user_id, guild_id, members (the ids of its views), shared_data, created_at, updated_at |
empty |
components |
each clicked control, by its custom_id |
id, view_id, interactions (the last 50), last_interaction |
empty |
modals |
each view whose modal was submitted, by the view's id | submissions (the last 50), last_submission |
empty |
persistent_views |
each persistent panel, by its persistence_key |
persistence_key, class_name, message_id, channel_id, guild_id, user_id, registered_at |
read back, with persistence set up |
application |
each slot, by its name | your reducers' slots, and scoped, which dispatch_scoped() writes |
the slots you save come back |
Closing a view removes its row, its components and modals entries, and its session once no view is left in
it. The six keys stay, even when one is left empty. A modals entry is written when a Modal built with
view_id= is submitted, as a form's text fields are. Saving a slot across a restart is set up per slot
(Persistence).
A screen's way back is not in the state. The navigation stack lives on the view object, and push() and pop()
hand it from screen to screen (Navigation).
Views, Sessions, and Navigation¶
| What it is | How long it lasts | More | |
|---|---|---|---|
| A view | The object behind one panel, on one message | Until it closes: exit(), its timeout, its message deleted, or a newer panel replacing it |
Lifecycle |
| A session | One per panel: the view and every screen pushed from it belong to it and share its shared_data |
Until its last screen closes | Session Data |
| Navigation | push() shows another screen on the same message, pop() builds the one before again, and replace() swaps the panel for a new message, with no way back |
As long as the panel: each screen hands the stack to the next | Navigation |
Next¶
The Five Pillars sorts every view setting by the question it answers: who can click, how many can be open, how long a view lives, who shares it, and where it goes next. State covers the store page by page.