Chuyển đến nội dung
Skillpedia
Lập trình chung75k · #2887

immutable-patterns

Skill này làm gì

Skill này rà soát mã JavaScript sửa trực tiếp các object và mảng. Skill dành cho lập trình viên quản lý dữ liệu hoặc state dùng chung trong ứng dụng.

Khi nào nên dùng

  • ✓Khi một lỗi xuất hiện vì dữ liệu bị thay đổi ở nơi không ngờ tới.
  • ✓Khi mã của bạn dùng push hoặc splice trên mảng dùng chung.
  • ✓Khi bạn dùng thư viện state và muốn phát hiện thay đổi đáng tin cậy.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/immutable-patterns/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể viết lại mã để cập nhật dữ liệu mà không làm thay đổi các object gốc không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm những chỗ object hoặc mảng bị thay đổi tại chỗ và gợi ý tạo bản sao đã sửa bằng cú pháp spread và các phương thức như map và filter.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Cập nhật bất biến là gì?

Đó là tạo một object hoặc mảng mới có thay đổi, còn bản cũ giữ nguyên.

Vì sao cách này giúp gỡ lỗi?

Skill nói mỗi phiên bản dữ liệu là một object riêng, nên bạn có thể so sánh và thấy điều gì đã thay đổi.

Điều này quan trọng nhất ở đâu?

Skill nói nó đặc biệt quan trọng trong các công cụ quản lý state như Redux, Zustand hoặc signals.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2887
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự