declare type AnyObject = { [key: string | number | symbol]: any; }; declare type AnyArray = any[]; declare type AnyPrimitive = number | bigint | string | boolean | null | void | symbol; declare type AnyConnection = Connection; declare type Listener = () => void; declare type Unsubscribe = () => void; declare type Updater = (a: A) => A; declare type Update = (updater: Updater) => void; declare type Store = { getSnapshot(): A; setSnapshot(next: A): boolean; subscribe(onStoreChange?: Listener): Unsubscribe; }; interface Breakable { connect(): void; disconnect(): void; } declare class SuspendedClosure implements Breakable { private resolution; private breaker; private onReady; private ready; constructor(); getSnapshot(): A; setSnapshot(value: A): void; /** * Connect the entry to the store by passing a subscribe function. Only * allow this in transitioning from unresolved to resolved. */ load(subscribe: () => Unsubscribe): void; connect(): void; disconnect(): void; } declare type ValueCache = { [cacheKey: string]: A; }; declare type InsertConnection = (store: Store, input: I, cacheKey: string) => SuspendedClosure; declare const INSERT: unique symbol; declare const CACHE: unique symbol; declare type Connection = { [INSERT]: InsertConnection; [CACHE]: ValueCache; }; declare const connection: (create: (store: Store, input: I) => Unsubscribe | void) => Connection; declare type BaseProxyValue = { toJSON(): A; toLens(): ProxyLens; }; declare type ArrayProxyValue = BaseProxyValue & Array>; declare type ObjectProxyValue = BaseProxyValue & { [K in keyof A]: ProxyValue; }; declare type ProxyValue = A extends AnyArray ? ArrayProxyValue : A extends AnyObject ? ObjectProxyValue : A extends AnyPrimitive ? A : never; declare type ShouldUpdateBoolean = boolean; declare type ShouldUpdateArray = (keyof A)[]; declare type ShouldUpdateObject = { [K in keyof A]?: A[K] extends any[] ? ShouldUpdate : ShouldUpdate; }; declare type ShouldUpdateFunction = (prev: A, next: A) => boolean; declare type ShouldUpdate = ShouldUpdateBoolean | ShouldUpdateFunction | ShouldUpdateArray | ShouldUpdateObject; declare type BaseProxyLens = { /** * Fetches the store for current focus. */ getStore(): Store; /** * Collapses the lens into a React hook. */ use(shouldUpdate?: ShouldUpdate): [ProxyValue, Update]; /** * A unique key for cases when you need a key. e.g. A React list. * * @example * const [list] = useLens(state); * * list.map(value => { * const lens = value.toLens(); * * return ; * }); */ $key: string; }; declare type ConnectionProxyLens = BaseProxyLens & (A extends Connection ? (input: I) => ProxyLens : {}); declare type ArrayProxyLens = BaseProxyLens & { [K in number]: ProxyLens; }; declare type ObjectProxyLens = BaseProxyLens & { [K in keyof A]: ProxyLens; }; declare type PrimitiveProxyLens = BaseProxyLens; declare type ProxyLens = A extends AnyConnection ? ConnectionProxyLens : A extends AnyObject ? ObjectProxyLens : A extends AnyArray ? ArrayProxyLens : A extends AnyPrimitive ? PrimitiveProxyLens : never; declare const createLens: (initialState: S) => ProxyLens; declare function useCreateLens(initialState: S | (() => S)): ProxyLens; declare type Lens = ProxyLens; export { Connection, Lens, Store, connection, createLens, useCreateLens };