Overview
iAtom (also exported as signal) is an immutable atom built on atom({ freeze: true }). Plain atom values are mutable by default — you can call .update() or mutate objects in place. With iAtom, every value written via .set() is deep-frozen, including the initial value and nested objects/arrays.
That turns accidental mutation into a runtime error (TypeError: Cannot assign to read only property in strict mode) instead of a silent bug where the UI never updates because nothing notified the atom.
The read API matches atom: call the atom, use .get(), or read .val. The write path is replace-only: pass a new value or an updater that returns a new object. There is no .update(). .reset() restores the frozen initial value (same reference — no clone). lock / unlock / freeze are inherited from atom.
API differences from atom
|
Member
|
Status
|
Notes
|
|---|---|---|
() / .get() / .val
| same | Reactive reads work identically. |
.set(value)
| same + freeze | Deep-freezes the incoming value before storing. |
.set(prev => next)
| same + freeze | Updater fn — use spread to derive new objects. |
.update()
| removed |
Does not exist on iAtom — use .set() with a new value.
|
.reset()
| iAtom only | Restores the frozen initial reference (no clone). |
.lock / .unlock
| inherited |
Same passcode semantics as atom.
|
Immutable config object
Every set() call deep-freezes the new value. Use spread in the updater to change one field without mutating the previous object.
Mutation fails — replace instead
Try a direct property write (blocked by freeze), then fix it with set() + spread. Nested objects are frozen too.
reset() to frozen initial
After edits, reset() restores the exact initial frozen reference.