nanostores
Version: 
A tiny (265 bytes) state manager for React/Preact/Vue/Svelte with many atomic tree-shakable stores
30 lines (27 loc) • 745 B
TypeScript
import type { MapStore } from '../map/index.js'
export interface MapCreator<
  Value extends object = any,
  Args extends any[] = []
> {
  (id: string, ...args: Args): MapStore<Value>
  build(id: string, ...args: Args): MapStore<Value>
  cache: {
    [id: string]: MapStore<{ id: string } & Value>
  }
}
/**
 * Create function to create map stores. It will be like a class for store.
 *
 * @param init Store’s initializer. Returns store destructor.
 */
export function mapCreator<
  Value extends object,
  Args extends any[] = [],
  StoreExt = Record<number | string | symbol, any>
>(
  init?: (
    store: MapStore<{ id: string } & Value> & StoreExt,
    id: string,
    ...args: Args
  ) => (() => void) | void
): MapCreator<Value, Args>