tshaddix / webext-redux

A set of utilities for building Redux applications in Web Extensions.
MIT License
1.22k stars 180 forks source link

Change store through background.js #216

Closed greghesp closed 2 months ago

greghesp commented 5 years ago

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?

davakh commented 5 years ago

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());