redux-saga-tools
Version:
A set of utility functions to write saga and reducers easily
35 lines (34 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const progress_action_1 = require("./progress-action");
const reducer_1 = require("./reducer");
function startAction(state, { type }) {
if (type == undefined) {
throw new Error('Invalid progress action: Missing "action" attribute');
}
return Object.assign({}, state, { [type]: { inProgress: true, error: undefined } });
}
function endAction(state, { type }) {
if (type == undefined) {
throw new Error('Invalid progress action: Missing "action" attribute');
}
return Object.assign({}, state, { [type]: { inProgress: false, error: undefined } });
}
function failAction(state, { type, error }) {
if (type == undefined) {
throw new Error('Invalid progress action: Missing "action" attribute');
}
return Object.assign({}, state, { [type]: { inProgress: false, error } });
}
function resetAction(state, { type }) {
if (type == undefined) {
throw new Error('Invalid progress action: Missing "action" attribute');
}
return Object.assign({}, state, { [type]: undefined });
}
exports.progressReducer = reducer_1.createReducer({}, {
[progress_action_1.ProgressActionType.START_ACTION]: startAction,
[progress_action_1.ProgressActionType.END_ACTION]: endAction,
[progress_action_1.ProgressActionType.FAIL_ACTION]: failAction,
[progress_action_1.ProgressActionType.RESET_ACTION]: resetAction,
});