CRITICAL: Use for Robius state management patterns. Triggers on: AppState, persistence, theme switch, 状态管理, Scope::with_data, save state, load state, serde, 状态持久化, 主题切换
View on GitHubZhangHanDong/makepad-skills
makepad-skills
January 22, 2026
Select agents to install to:
npx add-skill https://github.com/ZhangHanDong/makepad-skills/blob/main/skills/robius-state-management/SKILL.md -a claude-code --skill robius-state-managementInstallation paths:
.claude/skills/robius-state-management/# Robius State Management Skill
Best practices for state management and persistence in Makepad applications based on Robrix and Moly codebases.
**Source codebases:**
- **Robrix**: Matrix chat client - AppState, SelectedRoom, persistence via serde
- **Moly**: AI chat application - Central Store pattern, async initialization, Preferences
## Triggers
Use this skill when:
- Designing application state structure
- Implementing state persistence
- Passing state through widget tree
- Managing UI state across sessions
- Keywords: app state, makepad state, persistence, Scope::with_data, save state, load state
## Production Patterns
For production-ready state management patterns, see the `_base/` directory:
| Pattern | Description |
|---------|-------------|
| [06-global-registry](./_base/06-global-registry.md) | Global widget registry with Cx::set_global |
| [07-radio-navigation](./_base/07-radio-navigation.md) | Tab-style navigation with radio buttons |
| [10-state-machine](./_base/10-state-machine.md) | Enum-based state machine widgets |
| [11-theme-switching](./_base/11-theme-switching.md) | Multi-theme support with apply_over |
| [12-local-persistence](./_base/12-local-persistence.md) | Save/load user preferences |
## AppState Structure
### Core State Definition
```rust
use serde::{Serialize, Deserialize};
use std::collections::HashMap;
use matrix_sdk::ruma::OwnedRoomId;
/// App-wide state that is stored persistently across multiple app runs
/// and shared/updated across various parts of the app.
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct AppState {
/// The currently-selected room
pub selected_room: Option<SelectedRoom>,
/// Saved UI layout state for main view
pub saved_layout_state: SavedLayoutState,
/// Per-item saved states (e.g., per-space dock layouts)
pub saved_state_per_item: HashMap<OwnedRoomId, SavedLayoutState>,
/// Whether a user is currently logged in
#[serde(skip)] // Don't persist login