-
Notifications
You must be signed in to change notification settings - Fork 0
/
devtools.js
38 lines (32 loc) · 994 Bytes
/
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
export default function noRecoilDevTools(store) {
console.log({ 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.subscribe(function (action) {
if (!ignoreState) {
store.devtools.send(action || "set", store.getState());
} else {
ignoreState = false;
}
});
}
return store;
}