seitu
Version:
32 lines • 1.23 kB
text/typescript
import { i as Subscribable, n as Readable } from "./index-B0IeflOl.mjs";
//#region src/core/computed/index.d.ts
interface Computed<T> extends Readable<T>, Subscribable<T> {}
type Source<T = unknown> = Readable<T> & Subscribable<T>;
type SourceValues<S extends readonly Source[]> = { [K in keyof S]: S[K] extends Source<infer V> ? V : never; };
/**
* Derives a subscription from one source or many. `transform` is memoized on
* source references, so `get()` is stable until a source changes.
*
* @example
* ```ts twoslash
* import { createComputed, createStore } from 'seitu'
*
* const count = createStore({ a: 1, b: 2 })
* const sum = createComputed(count, s => s.a + s.b)
* sum.get() // 3
* ```
*
* @example
* ```ts twoslash
* import { createComputed, createStore } from 'seitu'
*
* const a = createStore(1)
* const b = createStore(2)
* const sum = createComputed([a, b], ([a, b]) => a + b)
* sum.get()
* ```
*/
declare function createComputed<S extends readonly Source[], R>(sources: [...S], transform: (values: SourceValues<S>) => R): Computed<R>;
declare function createComputed<T, R>(source: Source<T>, transform: (value: T) => R): Computed<R>;
//#endregion
export { createComputed as n, Computed as t };