You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
486 B
25 lines
486 B
7 years ago
|
const thunks = {};
|
||
|
|
||
|
export function createThunk(type) {
|
||
|
return function(payload = {}) {
|
||
|
return function(dispatch, getState) {
|
||
|
const thunk = thunks[type];
|
||
|
|
||
|
if (thunk) {
|
||
|
return thunk(getState, payload, dispatch);
|
||
|
}
|
||
|
|
||
|
throw Error(`Thunk handler has not been registered for ${type}`);
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function handleThunks(handlers) {
|
||
|
const types = Object.keys(handlers);
|
||
|
|
||
|
types.forEach((type) => {
|
||
|
thunks[type] = handlers[type];
|
||
|
});
|
||
|
}
|
||
|
|