MCPcopy Create free account
hub / github.com/Brainfock/Brainfock / spacesReducer

Function spacesReducer

src/common/workspace/reducer.js:43–99  ·  view source on GitHub ↗
(state = initialState, action)

Source from the content-addressed store, hash-verified

41});
42
43export default function spacesReducer(state = initialState, action) {
44 if (!(state instanceof InitialState)) return revive(state);
45
46 switch (action.type) {
47
48 case actions.CREATE:
49 return state
50 // lock form submit buttons etc.
51 .setIn(['formFields', 'loading'], true);
52
53 case actions.CREATE_SUCCESS:
54 return state
55 .update('list', list => list.unshift(Model({data: action.payload})))
56 .setIn(['formFields', 'loading'], false);
57
58 case actions.FIND_ONE:
59 return state
60 .setIn(['active', 'meta', 'isFetching'], true);
61
62 case actions.FIND_ONE_ERROR:
63 return state
64 .setIn(['active', 'meta', 'isFetching'], false)
65 .setIn(['active', 'meta', 'errors'], ['Something went wrong']);
66
67 case actions.FIND_ONE_SUCCESS:
68 return state
69 .set('active', new Model({
70 data: action.payload,
71 meta: new (Record({
72 isFetching: false,
73 hasError: false,
74 errors: List()
75 }))
76 }));
77
78 case actions.FIND:
79 return state
80 .setIn(['listMeta', 'isFetching'], true)
81 .update('list', list => list.clear());
82
83 case actions.FIND_ERROR:
84 return state.setIn(['listMeta', 'isFetching'], false);
85
86 case actions.FIND_SUCCESS: {
87 const newlist = action.payload.map((item) => {
88 return new Model({cid: getRandomString(), data: item});
89 });
90 return state
91 .update('list', list => list.clear())
92 .update('list', list => list.push(...newlist))
93 .setIn(['listMeta', 'isFetching'], false)
94 ;
95 }
96 }
97
98 return state;
99}

Callers

nothing calls this directly

Calls 3

ListClass · 0.85
getRandomStringFunction · 0.85
reviveFunction · 0.70

Tested by

no test coverage detected