Cross-Component Communication: Mailbox & Notifications
Overview
In a complex terminal app, components need to talk to each other without being directly connected. The Mailbox and Notification systems provide decoupled, asynchronous communication across the React tree.
Plain text
┌─────────────────────────────────────────────────────────────────────────────┐
│ COMMUNICATION PATTERNS │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ DIRECT (Props) - AVOID │ │
│ │ │ │
│ │ Parent ──► Child ──► Grandchild │ │
│ │ │ │ │ │ │
│ │ ▼ ▼ ▼ │ │
│ │ Props Props Props ❌ Tight coupling │ │
│ │ drilling drilling drilling ❌ Hard to refactor │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ MAILBOX PATTERN (PREFERRED) │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────────┐ ┌─────────┐ │ │
│ │ │ Tool A │───────►│ │◄───────│ Tool B │ │ │
│ │ │ (sends) │ │ MAILBOX │ │ (sends) │ │ │
│ │ └─────────┘ │ (central) │ └─────────┘ │ │
│ │ │ │ │ │
│ │ ┌─────────┐ │ │ ┌─────────┐ │ │
│ │ │ UI C │◄───────│ │───────►│ UI D │ │ │
│ │ │(receives)│ └─────────────┘ │(receives)│ │ │
│ │ └─────────┘ └─────────┘ │ │
│ │ │ │
│ │ ✅ Decoupled ✅ Async ✅ Type-safe │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ NOTIFICATION PATTERN (UI alerts) │ │
│ │ │ │
│ │ Any Component ──► NotificationContext ──► NotificationDisplay │ │
│ │ │ │
│ │ ✅ Global ✅ Auto-dismiss ✅ Priority │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘