1 | "use strict";
|
2 | var actions_1 = require('../actions');
|
3 | var assign = require('lodash.assign');
|
4 | function mutations(previousState, action) {
|
5 | if (previousState === void 0) { previousState = {}; }
|
6 | if (actions_1.isMutationInitAction(action)) {
|
7 | var newState = assign({}, previousState);
|
8 | newState[action.mutationId] = {
|
9 | mutationString: action.mutationString,
|
10 | mutation: action.mutation,
|
11 | variables: action.variables,
|
12 | loading: true,
|
13 | error: null,
|
14 | fragmentMap: action.fragmentMap,
|
15 | };
|
16 | return newState;
|
17 | }
|
18 | else if (actions_1.isMutationResultAction(action)) {
|
19 | var newState = assign({}, previousState);
|
20 | newState[action.mutationId] = assign({}, previousState[action.mutationId], {
|
21 | loading: false,
|
22 | error: null,
|
23 | });
|
24 | return newState;
|
25 | }
|
26 | else if (actions_1.isMutationErrorAction(action)) {
|
27 | var newState = assign({}, previousState);
|
28 | newState[action.mutationId] = assign({}, previousState[action.mutationId], {
|
29 | loading: false,
|
30 | error: action.error,
|
31 | });
|
32 | }
|
33 | else if (actions_1.isStoreResetAction(action)) {
|
34 | return {};
|
35 | }
|
36 | return previousState;
|
37 | }
|
38 | exports.mutations = mutations;
|
39 |
|
\ | No newline at end of file |