UNPKG

nrgy

Version:

The library for reactive programming using efficient computing and MVC/MVVM patterns

188 lines (168 loc) 6.4 kB
import { V as ValueEqualityFn, S as Signal, A as Atom, D as DestroyableAtom } from './types-CxOJPpKX.js'; import { S as SignalFn, A as AtomFn, E as EffectFn, a as Scope, b as AtomList, c as SignalOptions } from './types-jkBBq3Lp.js'; export { D as Destroyable, d as EffectAction, e as EffectContext, f as EffectOptions, g as EffectSubscription, h as ScopeTeardown, i as SharedScope, U as Unsubscribable } from './types-jkBBq3Lp.js'; import { A as AtomOptions } from './atom-DIp83xZa.js'; export { a as AtomUpdateError, W as WritableAtom, g as getAtomName, i as isAtom } from './atom-DIp83xZa.js'; export { D as DeclareStoreOptions, d as StateMutation, c as StateUpdates, S as Store, h as StoreFactory, a as StoreUpdate, b as StoreUpdates, e as createStore, f as createStoreUpdates, g as declareStateUpdates, i as declareStore } from './declareStore-Bkpf5vtW.js'; /** * The default equality function used for `atom` and `compute`, which treats values using identity semantics. */ declare const defaultEquals: ValueEqualityFn<unknown>; /** * Checks if the given `value` is a reactive `Signal`. */ declare function isSignal<T>(value: unknown): value is Signal<T>; /** * Returns a name of the given Signal */ declare function getSignalName(value: Signal<any>): string | undefined; /** * Destroys the signal */ declare function destroySignal(value: Signal<any>): void; /** * Checks if the signal is destroyed */ declare function isSignalDestroyed(value: Signal<any>): boolean; /** * Checks if the signal is subscribed */ declare function isSignalSubscribed(value: Signal<any>): boolean; /** * Factory to create `Signal` */ declare const signal: SignalFn; /** * Factory to create a writable `Atom` that can be set or updated directly. */ declare const atom: AtomFn; /** * A pure function that returns a value. */ type Computation<T> = () => T; /** * Options for `compute` */ type ComputeOptions<T> = { /** * Atom's name */ name?: string; /** * A function to determine if two values are equal. Defaults to `Object.is`. */ equal?: ValueEqualityFn<T>; }; /** * Create a computed `Atom` which derives a reactive value from an expression. * * @param computation A pure function that returns a value * @param options ComputeOptions */ declare function compute<T>(computation: Computation<T>, options?: ComputeOptions<T>): Atom<T>; /** * Creates a new effect */ declare const effect: EffectFn; /** * Creates a new synchronous effect */ declare const syncEffect: EffectFn; /** * An error thrown when one or more errors have occurred during the * `destroy` of a {@link Scope}. */ declare class ScopeDestructionError extends Error { readonly errors: unknown[]; constructor(errors: unknown[]); } /** * Creates `Scope` instance. */ declare function createScope(): Scope; /** * An atom that emits values and errors. */ type AtomSubject<T> = DestroyableAtom<T> & Readonly<{ /** Emits a new value */ next: (value: T) => void; /** Emits an error */ error: (error: unknown) => void; /** Returns an atom that can be used to destroy the subject */ asDestroyable(): DestroyableAtom<T>; }>; /** * Creates an atom that emits values and errors. * * @param initialValue The initial value * @param options AtomOptions */ declare function createAtomSubject<T>(initialValue: T, options?: AtomOptions<T>): AtomSubject<T>; /** * Run a function in a batch update context. * * It will defer all effect notifications until the function is finished. */ declare function batch(action: () => any): void; /** * Creates a new Atom which takes the latest values from source atoms * and combines them into an array. */ declare function combineAtoms<TValues extends unknown[]>(sources: AtomList<TValues>, options?: ComputeOptions<TValues>): Atom<TValues>; /** * Returns an atom which remembers the last emitter value. * * @param source - The source signal. */ declare function keepLastValue<T>(source: Signal<T>): DestroyableAtom<T | undefined>; /** * Returns an atom which remembers the last emitter value. * * @param source - The source signal. * @param initialValue - The initial value. */ declare function keepLastValue<T>(source: Signal<T>, initialValue: T): DestroyableAtom<T>; /** * Returns an atom which remembers the last emitter value. * * @param source - The source signal. * @param initialValue - The initial value. */ declare function keepLastValue<T>(source: Signal<T>, initialValue?: T): DestroyableAtom<T | undefined>; /** * Creates a new Atom which maps a source value by the provided mapping * function. */ declare function mapAtom<T>(source: Atom<T>, computation: (value: T) => T, options?: ComputeOptions<T>): Atom<T>; /** * Creates a new Atom which takes the latest values from source queries * and merges them into a single value. */ declare function mergeAtoms<TValues extends unknown[], TResult>(sources: [...{ [K in keyof TValues]: Atom<TValues[K]>; }], computation: (...values: TValues) => TResult, options?: ComputeOptions<TResult>): Atom<TResult>; type MixSignalsSources<TValues extends unknown[]> = [ ...{ [K in keyof TValues]: Signal<TValues[K]>; } ]; /** * Mixes multiple signals into a single signal */ declare function mixSignals<TValues extends unknown[]>(sources: MixSignalsSources<TValues>, options?: SignalOptions<TValues[number]>): Signal<TValues[number]>; /** * An equality function which compares two objects using their own keys */ declare const objectEquals: ValueEqualityFn<Readonly<Record<string, unknown>>>; /** * Runs all effects which are scheduled for the next microtask */ declare function runEffects(): void; /** * Returns a signal that emits the changes of the source atom. * * @param source - The source atom. * @param options - Options */ declare function signalChanges<T>(source: Atom<T>, options?: SignalOptions<T>): Signal<T>; export { Atom, AtomFn, AtomOptions, type AtomSubject, type Computation, type ComputeOptions, DestroyableAtom, EffectFn, Scope, ScopeDestructionError, Signal, SignalFn, SignalOptions, ValueEqualityFn, atom, batch, combineAtoms, compute, createAtomSubject, createScope, defaultEquals, destroySignal, effect, getSignalName, isSignal, isSignalDestroyed, isSignalSubscribed, keepLastValue, mapAtom, mergeAtoms, mixSignals, objectEquals, runEffects, signal, signalChanges, syncEffect };