import type { ReadableAtom } from '../atom/index.js' import type { AnyStore, Store, StoreValue } from '../map/index.js' import type { Task } from '../task/index.js' export type StoreValues = { [Index in keyof Stores]: StoreValue } type A = ReadableAtom type B = ReadableAtom type C = (...values: StoreValues<[A, B]>) => void interface Computed { /** * @deprecated Use `@nanostores/async`. */ ( stores: OriginStore, cb: (value: StoreValue) => Task ): ReadableAtom /** * @deprecated Use `@nanostores/async`. */ ( stores: [...OriginStores], cb: (...values: StoreValues) => Task ): ReadableAtom ( stores: OriginStore, cb: (value: StoreValue) => Value ): ReadableAtom /** * Create derived store, which use generates value from another stores. * * ```js * import { computed } from 'nanostores' * * import { $users } from './users.js' * * export const $admins = computed($users, users => { * return users.filter(user => user.isAdmin) * }) * ``` * * Use `@nanostores/async` for async function. */ ( stores: [...OriginStores], cb: (...values: StoreValues) => Task | Value ): ReadableAtom } export const computed: Computed interface Batched { ( stores: OriginStore, cb: (value: StoreValue) => Task | Value ): ReadableAtom /** * Create derived store, which use generates value from another stores. * * ```js * import { batched } from 'nanostores' * * const $sortBy = atom('id') * const $category = atom('') * * export const $link = batched([$sortBy, $category], (sortBy, category) => { * return `/api/entities?sortBy=${sortBy}&category=${category}` * }) * ``` */ ( stores: [...OriginStores], cb: (...values: StoreValues) => Task | Value ): ReadableAtom } export const batched: Batched