-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionHandlers.js
More file actions
30 lines (27 loc) · 837 Bytes
/
ActionHandlers.js
File metadata and controls
30 lines (27 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const actionHandlers = {
map: {},
add: (shard, type, callback) => {
if(!actionHandlers.map[shard]) actionHandlers.map[shard] = {}
actionHandlers.map[shard][type] = callback
},
remove: (shard, type) => {
if(!actionHandlers.map[shard]) return
delete actionHandlers.map[shard][type]
},
runReducer: (shard, state, action) => {
if(!actionHandlers.map[shard]) return state
if(actionHandlers.map[shard][action.type]){
const res = actionHandlers.map[shard][action.type](state, action);
if(typeof(res) === 'object') {
return res;
}
console.error('The actionHandler did NOT return a valid object, ignoring result ', state, action);
}
return state;
}
}
exports.default = actionHandlers;