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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With