mobx

关于 MobX 的专家说明,MobX 是基于透明响应式编程的状态管理库。适用于帮助开发者在 React 应用中使用可观察状态、自动依赖跟踪、计算值、用于状态变更的动作以及用于副作用的反应,以实现状态变化时 UI 自动更新的资料与实践建议。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "mobx":https://skillpi.com/zh/skills/deepskill-211c68b4a8042bbbb7c9d7548d3d5f20b0ec95a0686dc3ef910541556a5c0b60。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

关于 MobX 的专家说明,MobX 是基于透明响应式编程的状态管理库。适用于帮助开发者在 React 应用中使用可观察状态、自动依赖跟踪、计算值、用于状态变更的动作以及用于副作用的反应,以实现状态变化时 UI 自动更新的资料与实践建议。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: mobx
description: >-
  You are an expert in MobX, the simple and scalable state management library
  based on transparent reactive programming. You help developers build React
  applications with observable state, automatic tracking of dependencies,
  computed values, actions for state mutations, and reactions for side effects
  — providing a natural, class-based or functional approach where the UI
  automatically updates when state changes without manual subscriptions.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Frontend Development
  tags:
    - react
    - state-management
    - observable
    - reactive
    - proxy
    - automatic

MobX — Reactive State Management

You are an expert in MobX, the simple and scalable state management library based on transparent reactive programming. You help developers build React applications with observable state, automatic tracking of dependencies, computed values, actions for state mutations, and reactions for side effects — providing a natural, class-based or functional approach where the UI automatically updates when state changes without manual subscriptions.

Core Capabilities

Observable Store

import { makeAutoObservable, runInAction, reaction, autorun } from "mobx";
import { observer } from "mobx-react-lite";

class TodoStore {
  todos: Todo[] = [];
  filter: "all" | "active" | "done" = "all";
  isLoading = false;

  constructor() {
    makeAutoObservable(this);             // Auto-detect observables, computeds, actions
  }

  // Computed (auto-cached, updates when dependencies change)
  get filteredTodos() {
    switch (this.filter) {
      case "active": return this.todos.filter(t => !t.done);
      case "done": return this.todos.filter(t => t.done);
      default: return this.todos;
    }
  }

  get stats() {
    return {
      total: this.todos.length,
      done: this.todos.filter(t => t.done).length,
      remaining: this.todos.filter(t => !t.done).length,
    };
  }

  // Actions (state mutations)
  addTodo(text: string) {
    this.todos.push({ id: crypto.randomUUID(), text, done: false });
  }

  toggleTodo(id: string) {
    const todo = this.todos.find(t => t.id === id);
    if (todo) todo.done = !todo.done;     // Direct mutation — MobX tracks it
  }

  removeTodo(id: string) {
    this.todos = this.todos.filter(t => t.id !== id);
  }

  // Async action
  async fetchTodos() {
    this.isLoading = true;
    try {
      const response = await fetch("/api/todos");
      const data = await response.json();
      runInAction(() => {                 // Wrap post-await mutations
        this.todos = data;
        this.isLoading = false;
      });
    } catch {
      runInAction(() => { this.isLoading = false; });
    }
  }
}

const todoStore = new TodoStore();

// Observer component — auto-tracks which observables are used
const TodoList = observer(() => {
  const { filteredTodos, stats, isLoading } = todoStore;

  if (isLoading) return <Spinner />;

  return (
    <div>
      <p>{stats.remaining} remaining</p>
      <ul>
        {filteredTodos.map(t => (
          <li key={t.id} onClick={() => todoStore.toggleTodo(t.id)}
            style={{ textDecoration: t.done ? "line-through" : "none" }}>
            {t.text}
          </li>
        ))}
      </ul>
    </div>
  );
});

// Reactions (side effects when state changes)
reaction(
  () => todoStore.stats.remaining,
  (remaining) => { document.title = `${remaining} todos left`; },
);

Installation

npm install mobx mobx-react-lite

Best Practices

  1. makeAutoObservable — Use in constructor; automatically makes properties observable, getters computed, methods actions
  2. observer() — Wrap React components with observer; only re-renders when accessed observables change
  3. Direct mutations — Mutate state directly in actions (this.todos.push(...)) — MobX uses Proxy to track changes
  4. runInAction — Wrap state changes after await in runInAction(); required for async actions
  5. Computed values — Use getters for derived data; MobX caches results and recalculates only when dependencies change
  6. Reaction for side effects — Use reaction() or autorun() for logging, localStorage sync, API calls on state change
  7. Small stores — Create multiple domain stores (AuthStore, CartStore, UIStore); inject via React context or import
  8. Don't destructure — Don't destructure observables outside observer: const { count } = store breaks tracking; access via store.count

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 MobX 状态管理的完整知识体系,对 React 开发者具有明确实用价值
  • 涵盖核心概念、代码示例、最佳实践,帮助用户快速上手
触发精准95/100

亮点

  • description 清晰定义了 MobX 专家角色和适用场景
  • frontmatter 中 description 完整,覆盖 React 状态管理、observable、reactive 等关键词
结构规范90/100

亮点

  • 文档结构清晰,包含核心能力、代码示例、安装指南、最佳实践等章节
  • 提供完整的 TypeScript 示例,frontmatter 完整
执行可靠90/100

亮点

  • 代码示例语法正确,工具来源明确(mobx、mobx-react-lite)
  • 涵盖异步操作、错误处理、反应式副作用等关键场景
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 126 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。