-
Notifications
You must be signed in to change notification settings - Fork 1
/
devtools.js
48 lines (42 loc) · 1.24 KB
/
devtools.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module.exports = function atomDevTools(store) {
var extension =
window.__REDUX_DEVTOOLS_EXTENSION__ ||
(window.top && window.top.__REDUX_DEVTOOLS_EXTENSION__);
var ignoreState = false;
if (!extension) {
console.warn("Please install/enable Redux devtools extension");
store.devtools = null;
return store;
}
if (!store.devtools) {
store.devtools = extension.connect();
store.devtools.subscribe(function (message) {
if (message.type === "DISPATCH" && message.state) {
ignoreState =
message.payload.type === "JUMP_TO_ACTION" ||
message.payload.type === "JUMP_TO_STATE";
store.setState(JSON.parse(message.state));
}
});
store.devtools.init(store.getState());
store.addReducer(function devtoolsReducer(action, state) {
if (!ignoreState) {
if (action.type === "__ATOM_SET_STATE__") {
store.devtools.send(
{
type: action.type + " " + Object.keys(action.payload),
payload: action.payload,
},
state,
);
} else {
store.devtools.send(action, state);
}
} else {
ignoreState = false;
}
return state;
});
}
return store;
};