@mocanvas/state · class
declare class AtomMap<K, V>A reactive map from K to V, backed by one atom per key.
Methods · 15
clear(): voidRemove every entry.
constructor(name: string, entries?: Iterable<readonly [K, V]>)delete(key: K): booleanRemove key. Returns whether it was there.
deleteMany(keys: Iterable<K>): [K, V][]Remove several keys at once, in one transaction. Returns the keys that were actually there.
Deleting in a loop wakes every dependent once per key; a bulk delete — clearing a selection, dropping a page's shapes — should wake them once.
entries(): IterableIterator<[K, V]>The live entries, in insertion order.
forEach(fn: (value: V, key: K, map: AtomMap<K, V>) => void, thisArg?: unknown): voidget(key: K): V | undefinedThe value for key, or undefined when there is none.
getOrInsert(key: K, defaultValue: V): VThe value for key, inserting defaultValue first if there is none.
defaultValue is always evaluated by the caller; use
AtomMap.getOrInsertComputed when producing it is expensive.
getOrInsertComputed(key: K, create: (key: K) => V): VThe value for key, inserting create() first if there is none.
create runs **only** when the key is absent.
has(key: K): booleanWhether key has a value.
keys(): IterableIterator<K>The live keys, in insertion order.
set(key: K, value: V): thisSet key, returning the map so calls can be chained.
get size(): numberHow many entries the map holds.
update(key: K, fn: (prev: V) => V): VReplace key's value with fn applied to it. Throws if key is absent.
values(): IterableIterator<V>The live values, in insertion order.
Properties · 1
readonly name: stringmocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.