23 lines
658 B
JavaScript
23 lines
658 B
JavaScript
export function augmentGetState(originalGetState, selectors) {
|
|
const getState = () => originalGetState();
|
|
for (const s in selectors) {
|
|
getState[s] = (...args) => {
|
|
let result = selectors[s](originalGetState());
|
|
if (typeof result === 'function')
|
|
return result(...args);
|
|
return result;
|
|
};
|
|
}
|
|
return getState;
|
|
}
|
|
export function augmentDispatch(dispatch, actions) {
|
|
for (const a in actions) {
|
|
dispatch[a] = (...args) => {
|
|
const action = actions[a](...args);
|
|
dispatch(action);
|
|
return action;
|
|
};
|
|
}
|
|
return dispatch;
|
|
}
|