Skip to main content
The DeployStack frontend implements a global event bus system using the mitt library to enable efficient cross-component communication. This system provides immediate updates across components without requiring direct parent-child relationships or complex state management.

Overview

The event bus solves common frontend challenges such as:
  • Cross-component communication between unrelated components
  • Immediate UI updates when data changes in different parts of the application
  • Cache invalidation and data synchronization
  • Decoupled architecture for better maintainability

Architecture

Event Bus Setup

The event bus is configured globally in main.ts using Vue 3’s provide/inject pattern:

Type Safety

All events are strictly typed using TypeScript interfaces:

Storage Integration

The event bus includes built-in storage capabilities for persistent state management. When you use storage methods, they automatically emit events for reactive updates.

Storage Events

The storage system emits storage-changed events whenever data is modified:
📖 For detailed storage usage, see Frontend Storage System

Usage

Basic Implementation

1. Using the Composable

2. Component Lifecycle Management

Real-World Examples

Example 1: Team Management System

This example shows how the sidebar automatically updates when teams are created from the teams page.

Emitting Events (Team Creation)

Listening for Events (Sidebar Updates)

Example 2: Notification System

Triggering Notifications

Example 3: MCP Server Deployment Status

Event Naming Convention

The event bus follows a consistent naming pattern to ensure clarity and maintainability across the application.

Standard Pattern

This pattern makes events self-documenting and easy to understand at a glance.

Examples

Naming Guidelines

  • Use kebab-case: All event names should use lowercase with hyphens
  • Feature first: Start with the feature or domain name
  • Action second: End with the specific action or state change
  • Be specific: Avoid generic names like ‘update’ or ‘change’ without context
  • Past tense for completed actions: Use ‘created’, ‘updated’, ‘deleted’ for completed operations
  • Present tense for commands: Use ‘show’, ‘hide’, ‘clear’ for immediate actions

Best Practices

1. Event Type Definition

Always define event types in the EventBusEvents interface for type safety:

2. Memory Management

Always clean up event listeners to prevent memory leaks:

3. Error Handling

Wrap event handlers in try-catch blocks:

4. Debugging Events

Add logging for development:

Common Patterns

1. Data Synchronization

2. Cache Invalidation

3. UI State Updates

Performance Considerations

1. Event Frequency

Be mindful of high-frequency events:

2. Event Data Size

Keep event payloads small:

Testing

Unit Testing Events

Migration Guide

From Direct Component Communication

Before:
After:

Adding New Events

  1. Define the event type:
  1. Emit the event:
  1. Listen for the event:

Troubleshooting

Common Issues

  1. Events not firing: Check if the event name matches exactly
  2. Memory leaks: Ensure eventBus.off() is called in onUnmounted()
  3. TypeScript errors: Verify event types are defined in EventBusEvents
  4. Handler not called: Check if the listener was registered before the event was emitted

Debugging Tips

The global event bus system provides a powerful and type-safe way to handle cross-component communication in the DeployStack frontend, enabling immediate updates and better user experience.