// Type definitions for state-trooper 2.1 // Project: state-trooper // Definitions by: Andrew Goodale export interface Cursor { readonly path: string[]; deref(path?: string | string[]): T | null; replace(val: T | null, callback?: CursorCallback): void; set(val: Partial, callback?: CursorCallback): void; remove(callback?: CursorCallback): void; refine(path: string | string[]): Cursor; equals(other: any): boolean; fetch(): void; persist(): void; } export interface ArrayCursor extends Cursor> { add(val: T, callback?: CursorCallback): void; } export type CursorCallback = (cursor: Cursor, rootCursor: Cursor) => void; export type QueryDef = string | object; export interface DataStore { readonly fetcher?: (cursor: Cursor, rootCursor: Cursor, query?: QueryDef) => void; readonly persister?: (cursor: Cursor, update: StateUpdate, rootCursor: Cursor) => void; readonly initialFetch?: boolean; readonly query?: QueryDef; } export interface StateDescriptor { readonly state: T; readonly dataStore?: { [key: string]: DataStore }; readonly stakeout?: { [key: string]: Array }; } export type UpdateAction = 'set' | 'replace' | 'add' | 'remove'; export interface StateUpdate { readonly path: string[]; readonly action: UpdateAction; readonly value: any; } export type StakeoutHandler = ( cursor: Cursor, update: StateUpdate, rootCursor: Cursor ) => void; export function patrol(stateDesc: StateDescriptor): any; export function patrolRunLoop( stateDesc: StateDescriptor, updateHandler: (cursor: Cursor) => boolean | void ): Cursor; export function stakeout(path: string, handler: StakeoutHandler): void;