MCPcopy
hub / github.com/nanostores/nanostores / Effect

Interface Effect

effect/index.d.ts:4–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import type { AnyStore, Store, StoreValue } from '../index.js'
3
4interface Effect {
5 <OriginStore extends Store>(
6 stores: OriginStore,
7 cb: (value: StoreValue<OriginStore>) => (() => void) | void
8 ): () => void
9 /**
10 * Subscribe for multiple stores. Also you can define cleanup function
11 * to call on stores changes.
12 *
13 * ```js
14 * const $enabled = atom(true)
15 * const $interval = atom(1000)
16 *
17 * const cancelPing = effect([$enabled, $interval], (enabled, interval) => {
18 * if (!enabled) return
19 * const intervalId = setInterval(() => {
20 * sendPing()
21 * }, interval)
22 * return () => {
23 * clearInterval(intervalId)
24 * }
25 * })
26 * ```
27 */
28 <OriginStores extends AnyStore[]>(
29 stores: [...OriginStores],
30 cb: (...values: StoreValues<OriginStores>) => (() => void) | void

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected