redux-state-branch
Advanced tools
Comparing version 0.0.37 to 0.0.38
@@ -37,5 +37,9 @@ interface AnyAction<T = any> { | ||
export declare const selectorsFactory: <ItemT extends AnyItem, BranchStateT extends State<ItemT> = State<ItemT>>(branchName: string) => { | ||
/** Get all items */ | ||
all: <StateT>(state: StateT) => ItemT[]; | ||
/** Get an item by id */ | ||
byId: <StateT>(state: StateT, id?: string | null | undefined) => ItemT | undefined; | ||
/** Get items that meet a filter condition */ | ||
where: <StateT>(state: StateT, condition: (item: ItemT) => boolean) => ItemT[]; | ||
/** Get the top level meta content */ | ||
meta: <StateT>(state: StateT) => BranchStateT; | ||
@@ -45,5 +49,9 @@ }; | ||
protected branchName: string; | ||
/** Get all items */ | ||
all: <StateT>(state: StateT) => ItemT[]; | ||
/** Get an item by id */ | ||
byId: <StateT>(state: StateT, id?: string | null) => ItemT | undefined; | ||
/** Get an items that meet a filter condition */ | ||
where: <StateT>(state: StateT, condition: (item: ItemT) => boolean) => ItemT[]; | ||
/** Get the top level meta content */ | ||
meta: <StateT>(state: StateT) => BranchStateT; | ||
@@ -59,3 +67,3 @@ constructor(branchName: string); | ||
/** Create an item */ | ||
create: (items?: Partial<ItemT> | Partial<ItemT>[] | undefined, devToolsSuffix?: string | undefined) => { | ||
create: (items?: Partial<ItemT> | Partial<ItemT>[] | undefined, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -65,3 +73,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Update an item */ | ||
update: (items: ItemsT<ItemT>, devToolsSuffix?: string | undefined) => { | ||
update: (items: ItemsT<ItemT>, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -71,3 +79,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Remove an item */ | ||
remove: (items: string | string[] | Partial<ItemT> | Partial<ItemT>[], devToolsSuffix?: string | undefined) => { | ||
remove: (items: string | string[] | Partial<ItemT> | Partial<ItemT>[], typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -77,3 +85,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Replace an item */ | ||
replace: (items: ItemsT<ItemT>, devToolsSuffix?: string | undefined) => { | ||
replace: (items: ItemsT<ItemT>, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -83,3 +91,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Set meta content */ | ||
setMeta: (meta: Partial<BranchStateT>, devToolsSuffix?: string | undefined) => { | ||
setMeta: (meta: Partial<BranchStateT>, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -89,3 +97,3 @@ meta: Partial<BranchStateT>; | ||
/** Reset branch to initial state */ | ||
reset: (devToolsSuffix?: string | undefined) => { | ||
reset: (typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -100,3 +108,3 @@ }; | ||
/** Create an item */ | ||
create: (items?: Partial<ItemT> | Partial<ItemT>[] | undefined, devToolsSuffix?: string | undefined) => { | ||
create: (items?: Partial<ItemT> | Partial<ItemT>[] | undefined, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -106,3 +114,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Update an item */ | ||
update: (items: ItemsT<ItemT>, devToolsSuffix?: string | undefined) => { | ||
update: (items: ItemsT<ItemT>, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -112,3 +120,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Remove an item */ | ||
remove: (items: string | Partial<ItemT> | Partial<ItemT>[] | string[], devToolsSuffix?: string | undefined) => { | ||
remove: (items: string | Partial<ItemT> | Partial<ItemT>[] | string[], typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -118,3 +126,3 @@ items: PartialWithId<ItemT>[]; | ||
/** DEPRECATED, Use remove instead */ | ||
delete: (items: string | Partial<ItemT> | Partial<ItemT>[] | string[], devToolsSuffix?: string | undefined) => { | ||
delete: (items: string | Partial<ItemT> | Partial<ItemT>[] | string[], typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -124,3 +132,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Replace an item */ | ||
replace: (items: ItemsT<ItemT>, devToolsSuffix?: string | undefined) => { | ||
replace: (items: ItemsT<ItemT>, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -130,3 +138,3 @@ items: PartialWithId<ItemT>[]; | ||
/** Set meta content */ | ||
setMeta: (meta: Partial<BranchStateT>, devToolsSuffix?: string | undefined) => { | ||
setMeta: (meta: Partial<BranchStateT>, typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -136,3 +144,3 @@ meta: Partial<BranchStateT>; | ||
/** Reset branch to initial state */ | ||
reset: (devToolsSuffix?: string | undefined) => { | ||
reset: (typeSuffix?: string | undefined) => { | ||
type: string; | ||
@@ -142,9 +150,7 @@ }; | ||
} | ||
declare type ActionsMap = { | ||
export declare class StateBranch<ItemT extends AnyItem, BranchStateT extends State<ItemT>, ActionsT extends Actions<ItemT, BranchStateT> | { | ||
[key: string]: (...args: any) => AnyAction; | ||
}; | ||
declare type SelectorsMap = { | ||
}, SelectorsT extends Selectors<ItemT, BranchStateT> | { | ||
[key: string]: (...args: any) => any; | ||
}; | ||
export declare class StateBranch<ItemT extends AnyItem, BranchStateT extends State<ItemT>, ActionsT extends Actions<ItemT, BranchStateT> | ActionsMap, SelectorsT extends Selectors<ItemT, BranchStateT> | SelectorsMap, ConstantsT extends { | ||
}, ConstantsT extends { | ||
[key: string]: string; | ||
@@ -151,0 +157,0 @@ }, UtilsT extends { |
@@ -49,9 +49,13 @@ "use strict"; | ||
return { | ||
/** Get all items */ | ||
all: all, | ||
/** Get an item by id */ | ||
byId: function (state, id) { | ||
return state[branchName].items[id || '']; | ||
}, | ||
/** Get items that meet a filter condition */ | ||
where: function (state, condition) { | ||
return all(state).filter(condition); | ||
}, | ||
/** Get the top level meta content */ | ||
meta: function (state) { | ||
@@ -87,3 +91,3 @@ return state[branchName]; | ||
/** Create an item */ | ||
create: function (items, devToolsSuffix) { | ||
create: function (items, typeSuffix) { | ||
var ensureItem = (items || {}); | ||
@@ -97,3 +101,3 @@ var newCreateItems = ensureArray(ensureItem).map(function (item) { | ||
return { | ||
type: makeType(constant.CREATE, devToolsSuffix), | ||
type: makeType(constant.CREATE, typeSuffix), | ||
items: ensureArray(newCreateItems) | ||
@@ -103,5 +107,5 @@ }; | ||
/** Update an item */ | ||
update: function (items, devToolsSuffix) { | ||
update: function (items, typeSuffix) { | ||
return { | ||
type: makeType(constant.UPDATE, devToolsSuffix), | ||
type: makeType(constant.UPDATE, typeSuffix), | ||
items: ensureArray(items) | ||
@@ -111,6 +115,6 @@ }; | ||
/** Remove an item */ | ||
remove: function (items, devToolsSuffix) { | ||
remove: function (items, typeSuffix) { | ||
var wrappedItems = !Array.isArray(items) ? [items] : items; | ||
return { | ||
type: makeType(constant.REMOVE, devToolsSuffix), | ||
type: makeType(constant.REMOVE, typeSuffix), | ||
items: ensureArray(typeof wrappedItems[0] === 'string' | ||
@@ -122,5 +126,5 @@ ? wrappedItems.map(function (id) { return ({ id: id }); }) | ||
/** Replace an item */ | ||
replace: function (items, devToolsSuffix) { | ||
replace: function (items, typeSuffix) { | ||
return { | ||
type: makeType(constant.REPLACE, devToolsSuffix), | ||
type: makeType(constant.REPLACE, typeSuffix), | ||
items: ensureArray(items) | ||
@@ -130,5 +134,5 @@ }; | ||
/** Set meta content */ | ||
setMeta: function (meta, devToolsSuffix) { | ||
setMeta: function (meta, typeSuffix) { | ||
return { | ||
type: makeType(constant.SET_META, devToolsSuffix), | ||
type: makeType(constant.SET_META, typeSuffix), | ||
meta: meta | ||
@@ -138,4 +142,4 @@ }; | ||
/** Reset branch to initial state */ | ||
reset: function (devToolsSuffix) { return ({ | ||
type: makeType(constant.RESET, devToolsSuffix) | ||
reset: function (typeSuffix) { return ({ | ||
type: makeType(constant.RESET, typeSuffix) | ||
}); } | ||
@@ -153,5 +157,5 @@ }; | ||
this.update = update; | ||
this.delete = function (items, devToolsSuffix) { | ||
this.delete = function (items, typeSuffix) { | ||
console.log(branchName + ".action.delete is deprecated. Please use .remove instead."); | ||
return remove(items, devToolsSuffix); | ||
return remove(items, typeSuffix); | ||
}; | ||
@@ -168,23 +172,3 @@ this.remove = remove; | ||
function StateBranch(_a) { | ||
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, | ||
// @ts-ignore | ||
_e = _a.utils, | ||
// @ts-ignore | ||
utils = _e === void 0 ? {} : _e, | ||
// @ts-ignore | ||
_f = _a.defaultItem, | ||
// @ts-ignore | ||
defaultItem = _f === void 0 ? {} : _f, _g = _a.defaultState, defaultState = _g === void 0 ? { items: {} } : _g, _h = _a.reducer, reducer = _h === void 0 ? function (state, action) { return state; } : _h, _j = _a.generateId, customGenerateIdFunc = _j === void 0 ? generateId : _j; | ||
var name = _a.name, _b = _a.actions, ActionsConstructor = _b === void 0 ? Actions : _b, _c = _a.selectors, SelectorsConstructor = _c === void 0 ? Selectors : _c, _d = _a.constants, constants = _d === void 0 ? {} : _d, _e = _a.utils, utils = _e === void 0 ? {} : _e, _f = _a.defaultItem, defaultItem = _f === void 0 ? {} : _f, _g = _a.defaultState, defaultState = _g === void 0 ? { items: {} } : _g, _h = _a.reducer, reducer = _h === void 0 ? function (state, action) { return state; } : _h, _j = _a.generateId, customGenerateIdFunc = _j === void 0 ? generateId : _j; | ||
this.name = name; | ||
@@ -191,0 +175,0 @@ var defaultConstants = constantsFactory(name); |
{ | ||
"name": "redux-state-branch", | ||
"version": "0.0.37", | ||
"version": "0.0.38", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A redux wrapper for sane people.", |
Sorry, the diff of this file is not supported yet
48062
847