immer-draft-update
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "immer-draft-update" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-dd8056ba3a28e6ce313c9731bcf7781ddb4cc78ec9c2f701ce3a8a3c462f0adc. Verify the upstream source and version against https://skillhub.cn/skills/user_f1b049da/yfs20266680 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate immutable customer draft updates safely using Immer with a mutable-style API, suitable for scenarios that require using Immer, immutable drafts, and produce to update customer objects while avoiding direct mutation of object references.
Introduction source: third_party · user_f1b049da · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Not specified in the source documentation.
- Inputs and outputs
- Not specified in the source documentation.
- Software, accounts and paid services
- Not specified in the source documentation.
- Limits and differences
- Not specified in the source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: immer-draft-update
slug: yfs20266680
displayName: 不可变草稿更新
version: 1.0.0
summary: 用 Immer 安全更新客户草稿对象,避免直接改引用。
license: MIT
description: 用 Immer 以可变写法安全产出不可变的客户草稿更新,避免直接改对象引用。当用户需要 Immer、不可变草稿、produce 更新客户对象、避免直接 mutate state 时使用。不可变草稿更新(Immer)
灵感:能力工具箱 immer-draft(pkg: immer)。
用 produce 以「可变草稿」写法更新客户草稿,实际得到新对象引用,避免 Vue/React 状态被就地 mutate 导致视图不同步或撤销困难。
何时使用
- 客户草稿深层字段(联系人列表、地址嵌套)频繁改
- 需要可撤销/可对比的前后快照
- 不想手写大量展开运算
...
硬约束
- 依赖
immer;对外状态更新必须经produce(或produce封装),禁止对 store 里原对象直接赋值深层字段后当「已更新」。 produce回调内可以 push/splice;回调外把返回值赋回 state。- 与 localStorage 联用时:序列化存 produce 之后 的新对象。
- 不在
produce里发请求、不读 DOM;保持纯更新。 - TypeScript 项目保持草稿类型与客户类型一致。
推荐实现要点
import { produce } from 'immer'
export type CustomerDraft = {
id: string
name: string
mobile?: string
tags: string[]
contacts: { name: string; phone?: string }[]
}
export function patchDraft(
current: CustomerDraft,
recipe: (draft: CustomerDraft) => void,
): CustomerDraft {
return produce(current, recipe)
}
// 例:改名并追加标签
export function renameAndTag(current: CustomerDraft, name: string, tag: string) {
return patchDraft(current, (d) => {
d.name = name.trim()
if (tag && !d.tags.includes(tag)) d.tags.push(tag)
})
}
export function addContact(current: CustomerDraft, name: string, phone?: string) {
return patchDraft(current, (d) => {
d.contacts.push({ name, phone })
})
}
Agent 步骤
- 安装
immer,封装patchDraft与业务小函数。 - 所有草稿字段变更走封装;保存前可
JSON.stringify对比或写入存储。 - 自测:更新后
next !== prev,且prev.name未被改掉。
附加
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决前端状态管理中不可变更新的核心痛点,实用性强
- 适用于客户草稿深层字段频繁变更、需要撤销/快照的场景
Highlights
- 触发词精准完整,覆盖多种变体,边界清晰
Highlights
- Phase/步骤清晰,有出口条件,含端到端示例,frontmatter完整
Highlights
- 工具来源明确,参数正确,覆盖主要异常,不可逆操作有确认机制
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Not specified in the source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.