import { Unsubscribe } from "redux"; /** * The only thing all action types have in common is a string * property called type, which must be unique across all actions * handled by the same reducer. * * We adopt the additional (popular) pattern of collecting any * further data into a single payload property. This makes the * very common case of a single value very succinct. */ export interface Action { readonly type: T; readonly payload: P; } /** * Common features of an ActionCreator and a CollectionDefinition. */ export interface ActionDefinition { readonly type: T; reduce(state: S, payload: P): S; } export declare function definition(type: T, reduce: (state: S, payload: P) => S, func: F): F & ActionDefinition; /** * An ActionCreator is a function that creates actions and can * also be registered with a reducer. */ export interface ActionCreator extends ActionDefinition { (payload: P): Action; } /** * Defines an action, for later inclusion in a reducer. */ export declare function action(type: T, reduce: (state: S, payload: P) => S): ActionCreator; /** * Almost a minimal reducer, except it also knows a good * initial state, known as 'empty'. */ export interface Reducer { /** * Reduce function */ (state: S, action: A): S; /** * A suitable initial state */ empty: S; } /** * A reducer is a function that takes a state object and an action * and returns a modified state object. Here it is also equipped * with a method called action which allows multiple reducer * functions to be declaratively merged together into a single * function, and a store method that wraps Redux's createStore * to make it perfectly type-safe. * * Note that reducers are immutable - given a reducer x, calling * x.action(...) returns a new reducer combination rather than * modifying x. */ export interface ReducerBuilder extends Reducer { /** * Reduce function */ (state: S, action: A): S; /** * A suitable initial state */ empty: S; /** * Dummy member for use with typeof (does not have * a useful runtime value.) */ actionType: A; cursorType: Cursor; /** * Returns an enhanced ReducerBuilder capable of reducing * some additional action type. */ action(definition: ActionDefinition): ReducerBuilder>; /** * Creates a Redux store with extra type-safety. */ store(): Store; mixin(reducer2: Reducer): ReducerBuilder; } export declare function builder(empty: S, reduce: (state: S, action: A) => S): ReducerBuilder; /** * Creates a starter object from which a ReducerBuilder can be formed by * calling the action method. */ export declare function reducer(empty: S): ReducerBuilder; export interface Subscribable { subscribe(listener: () => void): Unsubscribe; } /** * Describes a minimal Redux-like store. Note that stores are not * immutable (that's their whole purpose) and therefore getState is * not pure (it may return a different value each time you call it). */ export interface Store extends Subscribable { dispatch(action: A1): A1; getState(): S; } /** * A pure representation of the state of a store or part of a store. * A cursor's value property never changes. Instead, the dispatch * method returns a new cursor representing the new state. * * Note that, unlike a traditional non-Redux cursor, updating is * always performed by dispatching an action. */ export interface Cursor { /** * The state at the time this cursor was created. */ readonly state: S; /** * Sends an action into the store's reducer, resulting in the * store updating, and a new cursor is returned representing * the new state. */ (action: A): Cursor; /** * Piping operator - allows left-to-write composition to navigate * down through a tree of cursors. This variant is for simple * references or properties. */ $(ref: (outer: Cursor) => Cursor): Cursor; } export declare function cursor(state: S, dispatch: (action: A) => Cursor): Cursor; /** * Takes a snapshot of a Redux-like store, making it into a pure cursor. */ export declare function snapshot(store: Store): Cursor; export interface ReferenceDefinition extends ActionDefinition { (outer: Cursor>): Cursor; update(action: A): Action; } export interface ReducerProvider { reduce: Reducer; } export declare type ReducerOrProvider = Reducer | ReducerProvider; export declare function getReducer(reducerOrProvider: ReducerOrProvider): Reducer; export declare function reference(type: T, reducerOrProvider: ReducerOrProvider, get: (state: S) => I, set?: (state: S, item: I) => S): ReferenceDefinition; export interface At { key: K; action: A; } export declare function collection(reducerOrProvider: ReducerOrProvider, get: (collection: C, key: K) => I | undefined, set: (collection: C, key: K, item: I) => C): ((key: K) => (outer: Cursor>>) => Cursor) & { update: (key: K, action: A) => Action<"AT", At>; } & ActionDefinition>; export declare function array(itemReducer: ReducerOrProvider): ((key: number) => (outer: Cursor>>) => Cursor) & { update: (key: number, action: A) => Action<"AT", At>; } & ActionDefinition>; export declare function objectByString(itemReducer: ReducerOrProvider): ((key: string) => (outer: Cursor<{ [key: string]: I; }, Action<"AT", At>>) => Cursor) & { update: (key: string, action: A) => Action<"AT", At>; } & ActionDefinition<{ [key: string]: I; }, "AT", At>; export declare function objectByNumber(itemReducer: ReducerOrProvider): ((key: number) => (outer: Cursor<{ [key: number]: I; }, Action<"AT", At>>) => Cursor) & { update: (key: number, action: A) => Action<"AT", At>; } & ActionDefinition<{ [key: number]: I; }, "AT", At>; export declare function removeFromObjectByString(): ActionCreator<{ [key: string]: I; }, "REMOVE", string>; export declare function removeFromObjectByNumber(): ActionCreator<{ [key: number]: I; }, "REMOVE", number>; export declare type Replace = Action<"REPLACE", V>; /** * Defines the reducer for a value that can only be assigned a whole new value. * It only supports the action "REPLACE" whose payload is the replacement value. */ export declare function primitive(): ReducerBuilder>; /** * Action that replaces a whole value, supported by primitives */ export declare function replace(value: T): Replace; /** * Property is just a type alias for a cursor to a primitive */ export declare type Property = Cursor>; /** * Defines a property, which is a simple value that can be * replaced with a new value. It uses the primitive reducer. */ export declare function property(type: T, fetch: (state: S) => V, reduce?: (state: S, payload: V) => S): ReferenceDefinition>; /** * Basic substitute for Object.assign */ export declare function assign(target: T, source1: S1, source2: S2): T & S1 & S2; export declare function assign(target: T, source1: S1): T & S1; /** * Pretty good subsitute for object spread syntax. Instead of: * * { ...book, title } * * say: * * amend(book, { title }) */ export declare function amend(o1: O1, o2: O2): {} & O1 & O2;