-
Notifications
You must be signed in to change notification settings - Fork 139
/
devtools.js
33 lines (28 loc) · 925 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
module.exports = function unistoreDevTools(store) {
var extension = window.__REDUX_DEVTOOLS_EXTENSION__ || 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), true);
}
});
store.devtools.init(store.getState());
store.subscribe(function (state, action) {
var actionName = action && action.name || 'setState';
if (!ignoreState) {
store.devtools.send(actionName, state);
} else {
ignoreState = false;
}
});
}
return store;
}