Skip to content

Commit 598c160

Browse files
committed
Allow only one listener to be subscribed to the background store
1 parent 854809d commit 598c160

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/app/store/createDevStore.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function createDevToolsStore(onDispatch) {
66
skippedActions: {},
77
currentStateIndex: 0
88
};
9-
let listeners = [];
9+
let handleChangeState = null;
1010
let initiated = false;
1111

1212
function dispatch(action) {
@@ -24,23 +24,21 @@ export default function createDevToolsStore(onDispatch) {
2424

2525
function setState(state) {
2626
currentState = state;
27-
listeners.forEach(listener => listener());
28-
initiated = true;
27+
if (handleChangeState) handleChangeState();
28+
if (!initiated) initiated = true;
2929
}
3030

3131
function subscribe(listener) {
32-
listeners.push(listener);
32+
handleChangeState = listener;
3333

3434
return function unsubscribe() {
35-
const index = listeners.indexOf(listener);
36-
listeners.splice(index, 1);
35+
handleChangeState = null;
3736
};
3837
}
3938

4039
return {
4140
dispatch,
4241
getState,
43-
subscribe,
4442
liftedStore: {
4543
dispatch,
4644
getState,

0 commit comments

Comments
 (0)