一键导入
mobx
Guides state management implementation using MobX + tsyringe. Triggered when handling data models, state logic, or Store architecture.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guides state management implementation using MobX + tsyringe. Triggered when handling data models, state logic, or Store architecture.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Maintain package-level `agentmap.md` files as outline-level maps of the real file tree and core responsibilities. Use when package structure or responsibility boundaries change and the corresponding `agentmap.md` must be created or updated.
Review uncommitted code changes to find unreasonable design, unfinished requirements, potential bugs, missed reuse opportunities, and optimization opportunities. Use when the user asks for a review of pending, uncommitted, or unpublished code changes and expects both findings and concrete improvements.
Guides the generation, reading, and updating of agentmap.md files. This skill ensures a consistent and up-to-date codebase map for AI Agents.
Interacts with local browser via Chrome DevTools Protocol (only triggered after user explicitly requests to inspect, debug, or interact with pages open in Chrome)
Guides styling implementation using TailwindCSS + CSS Modules. Triggered when handling component styles, layout design, or CSS patterns.
Specialized for translating document files and their content into English. Triggered when localization, translation, or converting Chinese documents to English is requested.
| name | mobx |
| description | Guides state management implementation using MobX + tsyringe. Triggered when handling data models, state logic, or Store architecture. |
This skill provides mandatory specifications for using MobX and tsyringe (for dependency injection DI) for state management in this project.
makeAutoObservable).GlobalModel, Settings).import { makeAutoObservable } from 'mobx'
import { injectable } from 'tsyringe'
@injectable()
export default class FeatureModel {
count = 0
loading = false
constructor() {
// ✅ Use autoBind: true for convenient event handling
makeAutoObservable(this, {}, { autoBind: true })
}
increment() {
this.count++
}
async fetchData() {
this.loading = true
try {
// API call logic
} finally {
this.loading = false
}
}
}
import { singleton } from 'tsyringe'
import { Settings } from '@/models'
@singleton()
export default class GlobalModel {
// ✅ Dependency injection via constructor
constructor(public settings: Settings) {}
init() {
this.settings.init()
}
off() {
this.settings.off()
}
}
For complex state management (more than 20 reactive variables), models should be split into smaller, focused sub-models and composed using DI.
// ✅ Recommended: split complex models into multiple sub-models and inject
@injectable()
export default class ComplexFeatureModel {
constructor(
public data: DataSubModel,
public ui: UISubModel,
public sync: SyncSubModel,
public util: Util
) {
// Note: exclude injected dependencies, don't make them observable
makeAutoObservable(this, { data: false, ui: false, sync: false, util: false }, { autoBind: true })
}
}
In sub-models, you can declare a non-observable property and bind the singleton GlobalModel instance in the constructor using the getGlobal utility function.
import { injectable } from 'tsyringe'
import { getGlobal } from '@/utils'
import type { GlobalModel } from '@/models'
@injectable()
export default class SubModel {
// ✅ Declare as non-reactive property
global = null as unknown as GlobalModel
constructor() {
makeAutoObservable(this, { global: false }, { autoBind: true })
// ✅ Bind instance via utility function
getGlobal(this.global)
}
}
In non-singleton models, container.resolve() creates new instances. To ensure sub-models access the correct parent instance, the parent must explicitly pass its reference.
Key Principles:
container.resolve(ParentModel) inside the constructor of a sub-model that the parent model depends on.All models should implement init() and off() methods for initialization setup and destruction cleanup.
@injectable()
export default class Index {
constructor(public util: Util) {
makeAutoObservable(this, { util: false }, { autoBind: true })
}
async init() {
// ✅ Collect cleanup functions (disposers) into util.acts array
this.util.acts = [
/* ... */
]
}
off() {
// ✅ Execute cleanup logic
this.util.off()
}
}
makeAutoObservable to exclude injected services/util classes (set to false), preventing them from becoming reactive.public keyword to automatically assign properties.{ autoBind: true } in makeAutoObservable.@injectable decorator will cause DI failure.off() will cause memory leaks.init().