redux-state-branch
Advanced tools
Comparing version 0.0.46 to 0.0.47
@@ -37,2 +37,3 @@ interface AnyAction<T = any> { | ||
export declare const selectors: <ItemT extends AnyItem, BranchStateT extends State<ItemT> = State<ItemT>>({ name }: { | ||
/** The name of your branch */ | ||
name: string; | ||
@@ -52,2 +53,18 @@ }) => { | ||
}) => ItemT | undefined; | ||
/** Gets an object map of unique ids to items {itemId: ItemT} */ | ||
mapById: <StateT>({ state }: { | ||
/** A global state object */ | ||
state: StateT; | ||
}) => { | ||
[key: string]: ItemT; | ||
}; | ||
/** Gets an object map of values of an item to an item {itemValueForKey: ItemT[]} */ | ||
mapByKey: <StateT>({ state, key }: { | ||
/** A global state object */ | ||
state: StateT; | ||
/** The key would would like to map the object by */ | ||
key: string; | ||
}) => { | ||
[key: string]: ItemT[]; | ||
}; | ||
/** Get items that meet a filter condition */ | ||
@@ -167,2 +184,18 @@ where: <StateT>({ state, callback }: { | ||
}) => ItemT | undefined; | ||
/** Gets an object map of unique ids to items {itemId: ItemT} */ | ||
mapById: <StateT>({ state }: { | ||
/** A global state object */ | ||
state: StateT; | ||
}) => { | ||
[key: string]: ItemT; | ||
}; | ||
/** Gets an object map of values of an item to an item {itemValueForKey: ItemT[]} */ | ||
mapByKey: <StateT>({ state, key }: { | ||
/** A global state object */ | ||
state: StateT; | ||
/** The key would would like to map the object by */ | ||
key: string; | ||
}) => { | ||
[key: string]: ItemT[]; | ||
}; | ||
/** Get items that meet a filter condition */ | ||
@@ -169,0 +202,0 @@ where: <StateT>({ state, callback }: { |
@@ -58,2 +58,17 @@ "use strict"; | ||
}, | ||
/** Gets an object map of unique ids to items {itemId: ItemT} */ | ||
mapById: function (_a) { | ||
var state = _a.state; | ||
return state[name].items; | ||
}, | ||
/** Gets an object map of values of an item to an item {itemValueForKey: ItemT[]} */ | ||
mapByKey: function (_a) { | ||
var state = _a.state, key = _a.key; | ||
var items = state[name].items; | ||
return Object.values(items).reduce(function (acc, item) { | ||
acc[item[key]] = acc[item[key]] || []; | ||
acc[item[key]].push(item); | ||
return acc; | ||
}, {}); | ||
}, | ||
/** Get items that meet a filter condition */ | ||
@@ -60,0 +75,0 @@ where: function (_a) { |
@@ -211,2 +211,12 @@ "use strict"; | ||
}); | ||
it('mapById', function () { | ||
var items = branch.select.mapById({ state: state }); | ||
expect(items).toEqual(branchState.items); | ||
}); | ||
it('mapByKey', function () { | ||
var _a; | ||
expect(branch.select.mapByKey({ state: state, key: 'name' })).toEqual((_a = {}, | ||
_a['James Friedman'] = [DEFAULT_STATE.items.testUser], | ||
_a)); | ||
}); | ||
it('where empty', function () { | ||
@@ -213,0 +223,0 @@ expect(branch.select.where({ |
{ | ||
"name": "redux-state-branch", | ||
"version": "0.0.46", | ||
"version": "0.0.47", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A redux wrapper for sane people.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47427
868