@mocanvas/state · class

AtomMap

declare class AtomMap<K, V>

A reactive map from K to V, backed by one atom per key.


Methods · 15

clear(): void

Remove every entry.

constructor(name: string, entries?: Iterable<readonly [K, V]>)
delete(key: K): boolean

Remove 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): void
get(key: K): V | undefined

The value for key, or undefined when there is none.

getOrInsert(key: K, defaultValue: V): V

The 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): V

The value for key, inserting create() first if there is none. create runs **only** when the key is absent.

has(key: K): boolean

Whether key has a value.

keys(): IterableIterator<K>

The live keys, in insertion order.

set(key: K, value: V): this

Set key, returning the map so calls can be chained.

get size(): number

How many entries the map holds.

update(key: K, fn: (prev: V) => V): V

Replace 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: string

mocanvas 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.