Skip to content

Commit ce7e477

Browse files
committed
Relay changes only when it is required by a monitor
1 parent dc45e73 commit ce7e477

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/browser/extension/inject/pageScript.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ window.devToolsExtension = function(config = {}) {
1010
let shouldInit = true;
1111
let lastAction;
1212
let errorOccurred = false;
13+
let isMonitored = false;
1314

1415
function stringify(obj) {
1516
return jsan.stringify(obj, function(key, value) {
@@ -65,6 +66,11 @@ window.devToolsExtension = function(config = {}) {
6566
store.liftedStore.dispatch(message.payload);
6667
} else if (message.type === 'UPDATE') {
6768
relay('STATE', store.liftedStore.getState());
69+
} else if (message.type === 'START') {
70+
isMonitored = true;
71+
relay('STATE', store.liftedStore.getState());
72+
} else if (message.type === 'STOP') {
73+
isMonitored = false;
6874
}
6975
}
7076

@@ -110,14 +116,15 @@ window.devToolsExtension = function(config = {}) {
110116

111117
// Detect when the tab is reactivated
112118
document.addEventListener('visibilitychange', function() {
113-
if (document.visibilityState === 'visible') {
119+
if (document.visibilityState === 'visible' && isMonitored) {
114120
shouldInit = true;
115121
relay('STATE', store.liftedStore.getState());
116122
}
117123
}, false);
118124
}
119125

120126
function monitorReducer(state = {}, action) {
127+
if (!isMonitored) return state;
121128
lastAction = action.type;
122129
if (lastAction === '@@redux/INIT' && store.liftedStore) {
123130
// Send new lifted state on hot-reloading
@@ -129,6 +136,7 @@ window.devToolsExtension = function(config = {}) {
129136
}
130137

131138
function handleChange(state, liftedState) {
139+
if (!isMonitored) return;
132140
const nextActionId = liftedState.nextActionId;
133141
const liftedAction = liftedState.actionsById[nextActionId - 1];
134142
const action = liftedAction.action;

0 commit comments

Comments
 (0)