webext-redux icon indicating copy to clipboard operation
webext-redux copied to clipboard

Change store through background.js

Open greghesp opened this issue 6 years ago • 1 comments

I have a situation whereby I use redux store to store a "loading" status.
User clicks a button on content script which triggers a dispatch to set loading to true, and this starts the background.js off performing API calls.

The issue I have, is if the user closes off the page where the content script is, and the API calls finish, the content script cannot trigger a dispatch to set loading to false, therefore the content script is stuck in loading.

Is it possible to trigger the dispatch from the background script?

greghesp avatar Jun 28 '19 12:06 greghesp

you're wrapping the store on background, and then you able use it as simple redux store. for example

const store = createStore(reducers, initialState, middlewares);

wrapStore(store, { portName: 'somePortName' });

store.dispatch(someAction());

davakh avatar Jul 12 '19 13:07 davakh