06. Cross-Component Events
The Problem
A Sales component may need to announce `InvoiceSaved` while an unrelated Dashboard component refreshes itself.
The React Difficulty
React does not provide a universal cross-component event bus. Applications usually introduce context, a state library, callbacks, or a custom event mechanism.
React Approach
window.dispatchEvent(new CustomEvent("invoiceSaved", {
detail: { invoiceId: 501 }
}));
useEffect(() => {
const handler = e => refreshDashboard(e.detail);
window.addEventListener("invoiceSaved", handler);
return () => window.removeEventListener("invoiceSaved", handler);
}, []);
MS Approach
ManySet provides a direct runtime-oriented approach for this recurring business-application task.
ms.ui.emit("invoiceSaved", { invoiceId: 501 });
ms.ui.listen("invoiceSaved", data => {
refreshDashboard(data);
});
Why this way is useful in business applications :
The comparison is intended to show where ManySet supplies a business-application abstraction around a recurring task, while keeping HTML and JavaScript visible and directly usable.
Key Point :
ManySet reduces the amount of framework-specific composition required for this particular task, without requiring the React/Angular mechanism to be represented as inherently wrong or incapable.