import { Store, StoreStateType } from '@zedux/core' import { AtomConfig, AtomApiPromise, AtomValueOrFactory, PromiseState, } from '../types/index' import { AtomTemplate } from '../classes/templates/AtomTemplate' import { AtomApi } from '../classes/AtomApi' export const atom: { // Query Atoms < State = any, Params extends any[] = [], Exports extends Record = Record >( key: string, value: (...params: Params) => AtomApi<{ Exports: Exports Promise: any State: Promise Store: undefined }>, config?: AtomConfig ): AtomTemplate<{ State: PromiseState Params: Params Exports: Exports Store: Store> Promise: Promise }> // Custom Stores < StoreType extends Store = Store, Params extends any[] = [], Exports extends Record = Record, PromiseType extends AtomApiPromise = undefined >( key: string, value: (...params: Params) => | StoreType | AtomApi<{ Exports: Exports Promise: PromiseType State: StoreStateType Store: StoreType }>, config?: AtomConfig> ): AtomTemplate<{ State: StoreStateType Params: Params Exports: Exports Store: StoreType Promise: PromiseType }> // Catch-all < State = any, Params extends any[] = [], Exports extends Record = Record, StoreType extends Store = Store, PromiseType extends AtomApiPromise = undefined >( key: string, value: AtomValueOrFactory<{ Exports: Exports Params: Params Promise: PromiseType State: State Store: StoreType }>, config?: AtomConfig ): AtomTemplate<{ Exports: Exports Params: Params Promise: PromiseType State: State Store: StoreType }> } = < State = any, Params extends any[] = [], Exports extends Record = Record, StoreType extends Store = Store, PromiseType extends AtomApiPromise = undefined >( key: string, value: AtomValueOrFactory<{ Exports: Exports Params: Params Promise: PromiseType State: State Store: StoreType }>, config?: AtomConfig ) => { if (DEV && !key) { throw new TypeError('Zedux: All atoms must have a key') } return new AtomTemplate<{ State: State Params: Params Exports: Exports Store: StoreType Promise: PromiseType }>(key, value, config) }