mirror of
https://github.com/fergalmoran/Readarr.git
synced 2026-01-27 02:54:44 +00:00
25 lines
486 B
JavaScript
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];
|
|
});
|
|
}
|
|
|