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 to T 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:
// in P's code on Monday
obs.publish({ foo: "bar" })
// in O's code on Tuesday
const { foo } = obs.listen();
// in P's code on Friday
obs.publish({ body: { foo: "bar" } });
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.
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