Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple React Applications communicating though a single redux store

Back story: Current my company has a "portal" where many different internal applications are developed independently and are then iframed into the site. There is a lot of chatter between the frames (usually checking a state or setting some state for other applications to see) which are all hosted on the same domain (not cross-domain). This approach works fine but recently we are considering moving to redux as this approach seems dirty and various teams are tossing a lot of data on window.top (globally). Would something like redux be able to handle multiple "applications" "communicating" in a way that is more uniform than just reading and setting variables on window.top or would this be an improper use of redux?

like image 383
TheSharpieOne Avatar asked Dec 23 '16 16:12

TheSharpieOne


People also ask

Can a React app have multiple Redux stores?

As with several other questions, it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to have only a single store. Having a single store enables using the Redux DevTools, makes persisting and rehydrating data simpler, and simplifies the subscription logic.

Is it true Redux can have single store in the entire apps?

Redux can have only a single store in your application. Whenever a store is created in Redux, you need to specify the reducer. A reducer is a function that returns the next state of app.

How many stores should a Redux application have?

As with several other questions, it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to have only a single store. Having a single store enables using the Redux DevTools, makes persisting and rehydrating data simpler, and simplifies the subscription logic.


1 Answers

Frames have different contexts. You'd have to refer to a parent store, e.g., expose the store (and its dispatch) via window. It's arguably cleaner than a random assortment of variables.

That said: if they're truly independent apps then I might instead opt for going truly independent via web sockets in each of the frames communicating via live updates delivered from a back end (Elixir, Node, etc.) that's well-suited for the task.

Doing so allows greater flexibility in separating out the apps (e.g., I just want app Foo running in its own window), getting the inter-frame comms onto a common bus so anything else that wants to look in on those messages can, etc.

like image 115
Dave Newton Avatar answered Sep 23 '22 19:09

Dave Newton