Skip to content

Collections

@starbeam/collections defines reactive versions of ordinary JavaScript objects and built-in collections. Use it for collection-shaped and object-shaped root state.

For the concept guide, start with Collections and objects.

Terminal window
pnpm add @starbeam/collections
import { reactive } from "@starbeam/collections";
HelperReturnsUse for
reactive.Map<K, V>()Map<K, V>keyed records, registries, caches, carts
reactive.Set<T>()Set<T>membership, selections, tags
reactive.array<T>(values)T[]ordered list state
reactive.object<T>(value)Tobject-shaped state
reactive.WeakMap<K, V>()WeakMap<K, V>object-keyed storage with weak ownership
reactive.WeakSet<T>()WeakSet<T>weak object membership

reactive.Map() and reactive.Set() create empty collections. Add entries with the normal JavaScript APIs.

reactive.object() and reactive.array() wrap an initial object or array and return the same JavaScript/TypeScript surface.

  • Prefer the named reactive import in user-facing examples.
  • Keep reactive storage private inside domain objects when the collection is an implementation detail.
  • Use Resources and lifecycle when the work has setup, sync, cleanup, or finalization.