In this article, I'm going to explain some ways to communicate between multiple applications and a particular way that I have chosen to use in my c...
For further actions, you may consider blocking this person and/or reporting abuse
Really nice article - well done!
There is, however, one problem with events: You only get notified in case of changes. Especially for your problem statement (sharing some global state) you'd be interested in the current snapshot when starting. So this assumes that all interested parties are already there when the state modifier starts submitting events. This, obviously, is in general not the case. Here, you'd end up with strange situations.
A more reliable solution would be to come up with events in both directions; i.e., one to get informed about the current snapshot (originating from interested microfrontends) and one to inform about changes to the snapshot (originating from the modifier).
One problem I see with the
windowed-observable
lib is that it hides what it changes onwindow
. Sure, now every microfrontend can embed this and presumably it still works (if more or less compatible versions are used) but what if somebody tries to use__shared__
for other purposes.Thanks again!
I was gonna say this but you arrived first, good point 😉 Well, you can always come up with an unique name and document it in your overall app architecture so that no one messes up with the shared thingy. Maybe this could even be configurable in your build process as an environment variable with the build number or what not. About having a snapshot of what has happened when your micro rendered is a must, so others can track/react to already triggered events.
This was really a nice article to read. Looking forward to more of your content.
Unfortunately it's not so easy. The name has to be known by the microfrontends which are build and deployed independently.
Hum... to solve it those keys/namespaces could be wrapped in another package which exposes only the communication API, and every micro-frontend uses this API
@vbarzana This kind of comment made my day, I'll try to create more content for sure!
I'm glad you liked it ❤️
Yep that's the main problem using the window someone may interfere in those keys 😥
@florianrappl it's a fair point, but at a certain point don't you have to simply trust the developers and hope that you hired the right people? Also, I think documentation, training, and on-boarding at the company should help tell people that you only communicate between microfrontends through the use of the recommended library (i.e. don't touch/read directly from window, use the library instead).
Nice work @luistak
Fala Luiz.
Tudo bem?
Cara primeiro dizer que gostei muito do seu post. Muito bom mesmo...
Queria tirar umas dúvidas com você a respeito da funcionalidade de "Retrieving latest event". Estou com uma necessidade aqui no trabalho de utilizar a comunicação entre MF's e pelo que li na documentação e vi em seu video a sua lib se encaixaria muito bem, porém, acredito que não estou sabendo utilizar muito bem essa funcionalidade de obter o último evento.
Poderia trocar uma ideia?
Valeu
This was one of the few articles worth reading in at least month. Thanks for the work you put into this. It's something I've banged my head for the past year and you just shined light on the darkest part of using this pattern. Thank you
This kind of comment really cheered me and pushed me to write more! I'm really glad you liked it, I held this article for a long time thinking it wasn't good enough.
I hope it helped at least a little in this matter o /
really nice, thank you for your share!
I like the window observable approach you've recommended, but I think it's important to list that it has a "con" to the approach: It misses type safety.
Sure, you can change the type in the interface from
T extends any
toT extends unknown
and that will help a little bit. But that doesn't solve the problem that occurs when a MicroFrontend falls out of date. To phrase that as a question:What does the observing MicroFrontend (let's call her "O") do when the publisher (let's call her MicroFrontend "P") changes the structure of the event that it's publishing?
For instance:
What happens?
Well, MicroFrontend O is going to have a runtime error since there was no requirement to re-compile/re-deploy MicroFront O after MicroFrontend P changed it's code.
Note: Consider subscribing to me, as I'll be writing my own article on this specific problem, and I'll likely refer to yours as a starting block. Thank you for your hard work @luistak.
Over that problem, I would suggest creating a new abstraction that will always handle both sides and exposes a consistent API that may not change
This is the same problem as
Rest api's
I've seen some folks solving this problem versioning their endpoints, so another solution would be versioning those namespaces to something like:
And each version would have different responses
I'm going to start a migration project next month and I'm gonna use micro-frontends to approach this project, one of the things I was considering for state management is the webworker solution here! One change I would make is that I'd have a redux store on the webworker and standardize redux over both apps, great article!
Hi José o/
Good luck with your project!
I don't really recommend using redux as a global state in a worker, consider sharing only the essential information
This quote from single-spa is awesome and also try to avoid "over-reduxing"
don't see the need for any of this which will add another platform dependent part into my application. Most react applications already use either mobx or redux, they are platform agnostic. I'm sure what ever library you use on Angular or Vue should expose observable or subscription api too.
Hi River!
The main message I was willing to pass was those types of sharing information between multiple micro-frontends, for sure your app may not need to do it what is also great!
Is there any better way to securely communicate a short data between two separate Angular Applications that don't run in the browser at the same time.
For example, send some JSON data from example.com/firstAngularapp to example.com/OtherAngularApp ?
For sure if they're at the same domain you can use localStorage or any relevant web storage/db to sync that data
Great article!
Thank you! I hope you liked it
I have a use case in which i have to communicate from iframe to parent and vice-versa
i know how to solve it but i am unable to change the existing code base of windowed-observable
We have to replace the window object with window.top and build it.
If there is any issue with this approach we can discuss
Nice article, thanks for sharing.
You are welcome o/ 😌
It's a pleasure to see you writing content! Great article and keep it up!