(initialValue: T, options?: SignalOptions<T>)
| 143 | export function atom<T>(initialValue: T, options?: SignalOptions<T>): Atom<T> |
| 144 | export function atom(initialValue?: undefined, options?: SignalOptions<undefined>): Atom<undefined> |
| 145 | export 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. |
no outgoing calls
no test coverage detected
searching dependent graphs…