本文へスキップ
Skillpedia
一般的なプログラミング75k · #2887

immutable-patterns

できること

このスキルは、オブジェクトや配列を直接編集している JavaScript のコードを見直します。アプリの共有データや状態を管理する開発者向けです。

使う場面

  • ✓データが予想外の場所で変わったためにバグが出るとき。
  • ✓共有された配列に push や splice を使っているとき。
  • ✓状態管理ライブラリを使い、変更の検出を確実にしたいとき。

スキルのリンク

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/immutable-patterns/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/immutable-patterns/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“元のオブジェクトを変えずに、データを更新するようにコードを書き直してもらえますか。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、オブジェクトや配列がその場で変更されている箇所を探し、スプレッド構文や map、filter などのメソッドで、変更を加えたコピーを作ることを提案します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Prefer immutable data patterns

Mutating shared objects makes it impossible to track where a value changed. When you update state immutably, each version of the data is a separate object — you can compare references to detect changes, time-travel debug, and know exactly which part of your code changed the data.

Quick Reference

  • Use spread (...) to create modified copies of objects and arrays
  • Prefer map(), filter(), and reduce() over push(), splice(), and direct assignment
  • Use Object.freeze() for configuration objects that should never change
  • Immutability is especially important in state management (Redux, Zustand, Signals)

Check

Find all places in this code where objects or arrays are mutated in place. Flag direct property assignments on function parameters and push/splice on arrays.

Fix

Replace in-place mutations with immutable patterns using spread operators and non-mutating array methods.

Explain

Explain immutable data patterns, why mutation causes bugs in shared state, and how spread and array methods enable immutability.

Code Review

Review scripts, client components, and browser execution paths related to Prefer immutable data patterns. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/immutable-patterns

よくある質問

イミュータブルな更新とは何ですか?

変更を加えた新しいオブジェクトや配列を作り、元のものは変えないことです。

なぜデバッグに役立つのですか?

データの各版は別々のオブジェクトなので、比べて何が変わったかを確認できるとこのスキルは説明しています。

どこで特に重要ですか?

Redux、Zustand、シグナルなどの状態管理ツールで特に重要だとしています。

詳細

作者による元の説明

Use when reviewing scripts, client components, bundles, or runtime behavior related to Prefer immutable data patterns. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.

repo: thedaviddias/Front-End-Checklist

人気

GitHubのスター
75k
ランキング
#2887
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル