redux-state-branch
Advanced tools
Comparing version 0.0.21 to 0.0.24
export declare const makeType: (prefix: string, suffix?: string | undefined) => string; | ||
export declare const ensureArray: (items: any) => any[]; | ||
export interface MapT { | ||
[key: string]: any; | ||
export interface MappedT<T = any> { | ||
[key: string]: T; | ||
} | ||
@@ -22,3 +22,3 @@ export declare type ItemT<T> = T & { | ||
items: ItemsT<T>; | ||
meta: MapT; | ||
meta: MappedT; | ||
} | ||
@@ -29,9 +29,9 @@ export interface IState { | ||
export declare const generateId: () => string; | ||
export declare class Selectors<T, BranchT> { | ||
export declare class Selectors<ItemType, BranchType> { | ||
protected name: string; | ||
constructor(name: string); | ||
byId<StateT>(state: StateT, id?: ID): T | void; | ||
all<StateT>(state: StateT): T[]; | ||
where<StateT>(state: StateT, condition: (item: ItemT<T>) => boolean): T[]; | ||
meta<StateT>(state: StateT): BranchT; | ||
byId<StateT>(state: StateT, id?: ID): ItemType | undefined; | ||
all<StateT>(state: StateT): ItemType[]; | ||
where<StateT>(state: StateT, condition: (item: ItemT<ItemType>) => boolean): ItemType[]; | ||
meta<StateT>(state: StateT): BranchType; | ||
} | ||
@@ -58,5 +58,5 @@ export declare class Actions<T> { | ||
}; | ||
setMeta(meta: MapT, devToolsSuffix?: string): { | ||
setMeta(meta: MappedT, devToolsSuffix?: string): { | ||
type: string; | ||
meta: MapT; | ||
meta: MappedT<any>; | ||
}; | ||
@@ -67,24 +67,24 @@ reset(devToolsSuffix?: string): { | ||
} | ||
interface IStateBranchOpts<T, A, S, C, U, B> { | ||
interface IStateBranchOpts<BranchStateType, ItemType, ActionsType = Actions<ItemType>, SelectorsType = Selectors<ItemType, BranchStateType>, ConstantsType = {}, UtilsType = {}> { | ||
name: string; | ||
actions?: new (constants: ConstantsT<C>, defaultItem: MapT) => A | Actions<T>; | ||
selectors?: new (name: string) => S | Selectors<T, B>; | ||
constants?: C; | ||
utils?: U; | ||
defaultItem?: MapT; | ||
defaultState?: MapT; | ||
reducer?: (state: IState, action: IAction<T>) => IState; | ||
actions?: new (constants: ConstantsT<ConstantsType>, defaultItem: MappedT) => ActionsType; | ||
selectors?: new (name: string) => SelectorsType; | ||
constants?: ConstantsType; | ||
utils?: UtilsType; | ||
defaultItem?: MappedT; | ||
defaultState?: MappedT; | ||
reducer?: (state: IState, action: IAction<ItemType>) => IState; | ||
} | ||
export declare class StateBranch<T, A, S, C, U, B> { | ||
export declare class StateBranch<ItemType, BranchStateType, ActionsType = Actions<ItemType>, SelectorsType = Selectors<ItemType, BranchStateType>, ConstantsType = {}, UtilsType = {}> { | ||
name: string; | ||
constant: ConstantsT<C>; | ||
util: U; | ||
action: A | Actions<T>; | ||
select: S | Selectors<T, B>; | ||
defaultItem: MapT; | ||
defaultState: MapT; | ||
protected extendedReducer: (state: IState, action: IAction<T>) => IState; | ||
constructor({ name, actions: ActionsConstructor, selectors: SelectorsConstructor, constants, utils, defaultItem, defaultState, reducer }: IStateBranchOpts<T, A, S, C, U, B>); | ||
reducer(state: IState | undefined, action: IAction<T>): MapT; | ||
constant: ConstantsT<ConstantsType>; | ||
util: UtilsType; | ||
action: ActionsType; | ||
select: SelectorsType; | ||
defaultItem: MappedT; | ||
defaultState: MappedT; | ||
protected extendedReducer: (state: IState, action: IAction<ItemType>) => IState; | ||
constructor({ name, actions: ActionsConstructor, selectors: SelectorsConstructor, constants, utils, defaultItem, defaultState, reducer }: IStateBranchOpts<BranchStateType, ItemType, ActionsType, SelectorsType, ConstantsType, UtilsType>); | ||
reducer(state: IState | undefined, action: IAction<ItemType>): MappedT<any>; | ||
} | ||
export {}; |
@@ -100,3 +100,15 @@ "use strict"; | ||
function StateBranch(_a) { | ||
var name = _a.name, _b = _a.actions, ActionsConstructor = _b === void 0 ? Actions : _b, _c = _a.selectors, SelectorsConstructor = _c === void 0 ? Selectors : _c, constants = _a.constants, utils = _a.utils, _d = _a.defaultItem, defaultItem = _d === void 0 ? {} : _d, _e = _a.defaultState, defaultState = _e === void 0 ? { items: {} } : _e, _f = _a.reducer, reducer = _f === void 0 ? function (state, action) { return state; } : _f; | ||
var name = _a.name, | ||
// @ts-ignore | ||
_b = _a.actions, | ||
// @ts-ignore | ||
ActionsConstructor = _b === void 0 ? Actions : _b, | ||
// @ts-ignore | ||
_c = _a.selectors, | ||
// @ts-ignore | ||
SelectorsConstructor = _c === void 0 ? Selectors : _c, | ||
// @ts-ignore | ||
_d = _a.constants, | ||
// @ts-ignore | ||
constants = _d === void 0 ? {} : _d, utils = _a.utils, _e = _a.defaultItem, defaultItem = _e === void 0 ? {} : _e, _f = _a.defaultState, defaultState = _f === void 0 ? { items: {} } : _f, _g = _a.reducer, reducer = _g === void 0 ? function (state, action) { return state; } : _g; | ||
this.name = name; | ||
@@ -103,0 +115,0 @@ this.constant = __assign({}, constants, { CREATE: name + "/CREATE", REPLACE: name + "/REPLACE", UPDATE: name + "/UPDATE", DELETE: name + "/DELETE", SET_META: name + "/SET_META", RESET: name + "/RESET" }); |
{ | ||
"name": "redux-state-branch", | ||
"version": "0.0.21", | ||
"version": "0.0.24", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A redux wrapper for sane people.", |
Sorry, the diff of this file is not supported yet
23646
449