MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / atom

Function atom

packages/shared/src/primitives.ts:145–165  ·  view source on GitHub ↗
(initialValue: T, options?: SignalOptions<T>)

Source from the content-addressed store, hash-verified

143export function atom<T>(initialValue: T, options?: SignalOptions<T>): Atom<T>
144export function atom(initialValue?: undefined, options?: SignalOptions<undefined>): Atom<undefined>
145export function atom<T>(initialValue: T, options?: SignalOptions<T>): Atom<T> {
146 let mutating = false
147
148 const equals = (options?.equals ?? equalFn) || (() => false)
149 const [atom, setter] = createSignal(initialValue, {
150 ...options,
151 equals: (a, b) => (mutating ? (mutating = false) : equals(a, b)),
152 }) as [Atom<T>, Setter<T>]
153
154 atom.update = setter
155 atom.trigger = () => {
156 mutating = true
157 setter(p => p)
158 }
159 atom.set = value => setter(() => value)
160 atom.peak = untrack.bind(void 0, atom) as any
161
162 Object.defineProperty(atom, 'value', {get: atom})
163
164 return atom
165}
166
167/**
168 * Creates a signal that will be activated for a given amount of time on every "ping" — a call to the listener function.

Callers 3

DisplayStructureTreeFunction · 0.90
attachDevtoolsOverlayFunction · 0.90
OverlayFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…