Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

js-immutability

/js-immutability

Pomaga pracować z niemutowalnymi danymi w JavaScript przez aktualizacje strukturalne, typy readonly i freeze tam, gdzie się opłaca.

Repozytorium
AI-SKILLS ↗
Licencja
MIT
Ostatnia zmiana repozytorium
05.09.2026

Ocena i bezpieczeństwo

90/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść25 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 05.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga pracować z niemutowalnymi danymi w JavaScript przez aktualizacje strukturalne, typy readonly i freeze tam, gdzie się opłaca.

Oryginalny opis (EN)

Work with immutable data in JavaScript through structural updates, readonly types, and freeze where it earns its cost. Use when managing shared or reactive state, or debugging bugs from unexpected mutation.

Jak działa

  1. Method
  2. Boundaries
Sekcje z nagłówków SKILL.md, w oryginale · 54 linii, 429 słów
Podgląd SKILL.md
---
name: js-immutability
description: Work with immutable data in JavaScript through structural updates, readonly types, and freeze where it earns its cost. Use when managing shared or reactive state, or debugging bugs from unexpected mutation.
---

# JS immutability

Shared mutable objects are where "something changed it and I do not know
what" bugs live, and where reactive frameworks silently fail to update.
Immutability, applied where it matters, makes state changes explicit and
traceable. The cost is copying, so apply it deliberately.

## Method

1. **Update by producing new values, not mutating.** Spread for shallow
   copies (`{ ...obj, field: next }`, `[...arr, item]`), and the
   non-mutating array methods (`map`, `filter`, `concat`, `slice`,
   `toSorted`/`toReversed`/`with`) over the mutating ones (`push`,
   `splice`, `sort`, which change in place). A `sort()` on a prop you did
   not own is a classic shared-state bug.
2. **Copy at the depth you actually change.** Spread is shallow: nested
   objects are still shared references, so mutating a nested field of a
   "copy" mutates the original too. Update the path you change
   (`{ ...s, user: { ...s.user, name } }`) or use a structural-sharing
   helper (immer's `produce` writes mutable-looking code that yields an
   immutable result) for deep updates without deep-copy cost.
3. **Encode intent in the type.** `readonly` properties, `ReadonlyArray`,
   and `Readonly<T>` make "do not mutate this" a compile error, not a
   convention (see ts-api-types). Accept `readonly` inputs on functions
   that only read; return frozen or readonly data from getters so callers
   cannot corrupt your state.
4. **Reserve `Object.freeze` for enforcement where it pays.** Freeze
   catches accidental mutation at runtime (throwing in strict mode), but
   it is shallow and has a cost; use it on config, constants, and
   development-mode state guards, not on every object in a hot path (see
   performance-optimization).
5. **Immutability is what makes reactivity and undo work.** Frameworks
   detect change by reference equality; mutating in place leaves the
   reference the same and the UI stale (see frontend-state). Immutable
   updates give you cheap change detection, time-travel/undo, and safe
   sharing across concurrent async work (the old response cannot mutate
   the new state).
6. **Do not fight it where mutation is local and clear.** Building an
   array in a tight loop with `push` before returning it, or mutating a
   freshly-created local object, is fine and faster; the discipline is
   about SHARED and reactive state, not a ban on all mutation.

## Boundaries

- Immutability trades allocation for safety; in hot paths over large data
  the copy cost is real, so measure and localize mutation there (see
  js-event-loop on not blocking the thread).
- `const` prevents reassignment, not mutation: `const obj = {}` still
  lets `obj.x = 1`. Immutability is about the value, `const` is about the
  binding.
- Deep-freezing or deep-cloning everything is over-application; target
  the state that is shared, reactive, or crosses async boundaries.

Wersje

W bazie nie ma innych skilli o nazwie js-immutability.

Migawka bazy z 13.11.2026 · wersja paczki 249642d523fc (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100functional
    Stosuje wzorce programowania funkcyjnego z niemutowalnymi danymi: czyste funkcje, kompozycję i wczesne zwroty, przy logice, transformacjach danych i błędach mutacji, w parze z tdd.
  • 90immutability-defaults
    Ustawia niezmienność jako domyślną, aby błędy aliasowania zamieniały się w błędy kompilacji lub puste operacje, przy projektowaniu struktur danych, aktualizacji stanu i wartości współdzielonych.
  • 90readonly
    Prowadzi badanie tylko do odczytu na podstawie dowodów z kodu i źródeł, bez zmian w systemie i bez zgadywania.
  • 100php
    Pomaga pisać PHP 8.2+ i pracować w kodzie Laravela oraz Symfony: strict types, enumy, klasy readonly, atrybuty, PSR i analiza statyczna PHPStan.
  • 100flutter-state-management
    Trzyma stan Flutter w notyfikatorach i blocach poza widgetami, z niemutowalnymi modelami i jawnymi stanami ładowania i błędu.
  • 100clojure-lisp-immutability
    Pomaga budować współbieżne, funkcyjne potoki przekształceń danych w Clojure, oparte na niezmienności i atomach.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.