Files
Readarr/frontend/src/Store/thunks.js
2017-11-26 15:09:45 -05:00

25 lines
486 B
JavaScript

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];
});
}