import * as Immutable from "immutable" import { clone } from "lodash" export type StateKey = S extends State ? (K extends string ? (K & keyof any) : never) : never export type StateArgs = keyof any | State | StateConstructor // export type ObjectType = [K,V] export type ObjectAsMap< T extends {}, K extends keyof T = keyof T, V extends T[K] = T[K] > = Immutable.Map export interface StateConstructor< S extends State, Key extends StateKey = StateKey > { readonly Key: Key new (o?: Partial): S fromJS?: (o: Partial) => S } //, K extends string = string export interface State { readonly type: T toJS?: () => any //[key:string]:any } export interface RootState extends State, Record { } /** * Function to patch an existing state * * @param {S} state * @param patches * @returns {S} */ export function patchState< S extends object = {}, SP extends Partial = Partial >(state: S, ...patches: Array): S { return Object.assign(clone(state), ...patches) }