globalAtomFamily

Signature
globalAtomFamily<T, K>(defaultFactory: (key: K) => T, options: GlobalAtomFamilyOptions): GlobalAtomFamily<T, K>

valdres Creates a keyed collection of cross-store singleton atoms

Combines atomFamily and globalAtom: each member is keyed by a parameter, and each member's value is shared across every store that touches it.

options.name is required — it is the family's global address. Re-defining a family under the same name returns the existing family instead of creating a second one. The first definition wins: its default and options remain active, and a development build warns that the later definition was ignored. This makes hot-module re-evaluation safe without silently changing live global state. A detectable contract mismatch, such as reusing an atom's name or changing the detectable keyOf arity, throws instead.

Usage

import { globalAtomFamily } from "valdres"

const featureFlagAtom = globalAtomFamily((key: string) => false, {
    name: "app/feature-flags",
})

featureFlagAtom("dark-mode").setSelf(true)

Same call shape as atomFamily — the only difference is that options.name is required instead of optional.

Each member carries the same getSelf / setSelf / resetSelf accessors as a plain globalAtom:

const flag = featureFlagAtom("dark-mode")
flag.getSelf()   // read without a Store handle
flag.setSelf(true)

Parameters

globalAtomFamily accepts the same options as atomFamily (keyOf, plus every AtomOptions field) as GlobalAtomFamilyOptions — identical to AtomFamilyOptions, except name is required instead of optional.

See also