跳到正文
Skillpedia
通用编程48k · #5644

robius-state-management

它能做什么

这项技能可以帮助你组织并保存应用中的重要信息,例如屏幕设置和用户偏好,以便之后再次使用。它能确保应用在关闭并重新打开后,状态依然保持不变。

适用场景

  • ✓当你在设计应用如何存储信息时。
  • ✓当你需要保存用户设置时。
  • ✓当你需要在不同使用会话之间管理屏幕上显示的内容时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/robius-state-management/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/robius-state-management/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我该如何保存屏幕设置,让我下次打开应用时它们还能保持原样?”

每周 5 个新技能,1 分钟读完。

工作原理

它使用名为 “serde” 的系统,把应用数据转换成可以保存到磁盘上的格式。当应用需要这些数据时,再把它们重新加载到内存中。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Supporting material availability

This catalog copy contains the inline guidance below, but does not include the following supporting paths. They are external prerequisites, not bundled files:

  • <support-root>/references/persistence-patterns.md
  • <support-root>/references/state-structures.md
  • <support-root>/references/moly-state-patterns.md

Ask for the original supporting material or an existing installation before using a step that depends on these paths; this catalog does not identify a verified download source for them. Resolve each path relative to that installation, inspect its contents, and verify any applicable license and execution prerequisites. Do not run a command or claim a referenced procedure was followed until its required file exists. Do not fabricate the missing scripts or treat an unrelated file with the same name as equivalent. Independent steps fully documented here can proceed within the user’s authorized scope; report any dependent step as unavailable.

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

When to Use

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 Global widget registry with Cx::set_global
07-radio-navigation Tab-style navigation with radio buttons
10-state-machine Enum-based state machine widgets
11-theme-switching Multi-theme support with apply_over
12-local-persistence Save/load user preferences

AppState Structure

Core State Definition

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 state
    pub logged_in: bool,
}

/// Represents a currently selected item
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SelectedRoom {
    JoinedRoom { room_name_id: RoomNameId },
    InvitedRoom { room_name_id: RoomNameId },
    Space { space_name_id: RoomNameId },
}

impl SelectedRoom {
    pub fn room_id(&self) -> &OwnedRoomId {
        match self {
            Self::JoinedRoom { room_name_id } => room_name_id.room_id(),
            Self::InvitedRoom { room_name_id } => room_name_id.room_id(),
            Self::Space { space_name_id } => space_name_id.room_id(),
        }
    }

    /// Upgrade from invited to joined state
    pub fn upgrade_invite_to_joined(&mut self, room_id: &RoomId) -> bool {
        match self {
            Self::InvitedRoom { room_name_id } if room_name_id.room_id() == room_id => {
                let name = room_name_id.clone();
                *self = Self::JoinedRoom { room_name_id: name };
                true
            }
            _ => false,
        }
    }
}

// Equality based on room_id only
impl PartialEq for SelectedRoom {
    fn eq(&self, other: &Self) -> bool {
        self.room_id() == other.room_id()
    }
}
impl Eq for SelectedRoom {}

Layout/Dock State Persistence

/// A snapshot of UI layout state for restoration
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct SavedLayoutState {
    /// All items contained in the layout, keyed by ID
    pub layout_items: HashMap<LiveIdSerde, LayoutItemSerde>,

    /// Items currently open, keyed by ID
    pub open_items: HashMap<LiveIdSerde, SelectedRoom>,

    /// Order items were opened (chronological)

…
常见问题

应用中的“状态”是什么?

状态是应用在某一时刻正常运行所需的全部信息,例如打开了哪些标签页、输入了什么文字、选择了哪个主题。

为什么保存状态很重要?

保存状态后,应用可以记住用户上次停留的位置,用户每次打开应用时都无需重新设置,从而提升使用体验。

什么是“持久化”?

持久化是指让应用的数据被保存下来,即使关闭应用也不会丢失,类似于把文档保存到文件中。

详情

作者的原始描述

CRITICAL: Use for Robius state management patterns. Triggers on: AppState, persistence, theme switch, 状态管理, Scope::with_data, save state, load state, serde, 状态持久化, 主题切换

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5644
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能