Skip to content

Commit f1497be

Browse files
author
Lasim
committed
docs(event-bus): enhance event bus documentation with naming conventions and best practices
1 parent ad7323e commit f1497be

2 files changed

Lines changed: 46 additions & 35 deletions

File tree

docs/development/frontend/architecture.mdx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -268,27 +268,9 @@ User Interaction → View → Service → API
268268

269269
### Event-Driven Updates
270270

271-
The application uses an **event bus** for cross-component communication without direct coupling.
271+
The application uses an **event bus** for cross-component communication without direct coupling. This enables real-time updates across unrelated components, cache invalidation signals, global notifications, and feature-to-feature communication.
272272

273-
Read more about the global event bus in the [Event Bus Documentation](/development/frontend/event-bus).
274-
275-
#### Event Bus Usage
276-
277-
- Real-time updates across unrelated components
278-
- Cache invalidation signals
279-
- Global notifications
280-
- Feature-to-feature communication
281-
282-
#### Event Naming Convention
283-
284-
```
285-
{feature}-{action}
286-
```
287-
288-
Examples:
289-
- `teams-updated`
290-
- `credential-deleted`
291-
- `mcp-server-deployed`
273+
For complete details on the event bus system, including usage patterns, naming conventions, and implementation examples, see the [Event Bus Documentation](/development/frontend/event-bus).
292274

293275
## Component Implementation Standards
294276

docs/development/frontend/event-bus.mdx

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,28 +321,57 @@ onUnmounted(() => {
321321
</script>
322322
```
323323

324-
## Best Practices
324+
## Event Naming Convention
325+
326+
The event bus follows a consistent naming pattern to ensure clarity and maintainability across the application.
325327

326-
### 1. Event Naming Convention
328+
### Standard Pattern
327329

328-
Use descriptive, action-based names with consistent patterns:
330+
```
331+
{feature}-{action}
332+
```
333+
334+
This pattern makes events self-documenting and easy to understand at a glance.
335+
336+
### Examples
329337

330338
```typescript
331-
// Good
339+
// Team-related events
332340
'teams-updated'
333-
'user-profile-changed'
341+
'team-created'
342+
'team-deleted'
343+
'team-selected'
344+
345+
// Credential events
346+
'credentials-updated'
347+
'credential-created'
348+
'credential-deleted'
349+
350+
// MCP server events
334351
'mcp-server-deployed'
335-
'notification-show'
352+
'mcp-server-installed'
353+
'mcp-installation-removed'
336354

337-
// Avoid
338-
'update'
339-
'change'
340-
'event1'
355+
// System events
356+
'notification-show'
357+
'storage-changed'
358+
'cache-cleared'
341359
```
342360

343-
### 2. Type Safety
361+
### Naming Guidelines
362+
363+
- **Use kebab-case**: All event names should use lowercase with hyphens
364+
- **Feature first**: Start with the feature or domain name
365+
- **Action second**: End with the specific action or state change
366+
- **Be specific**: Avoid generic names like 'update' or 'change' without context
367+
- **Past tense for completed actions**: Use 'created', 'updated', 'deleted' for completed operations
368+
- **Present tense for commands**: Use 'show', 'hide', 'clear' for immediate actions
369+
370+
## Best Practices
371+
372+
### 1. Event Type Definition
344373

345-
Always define event types in the `EventBusEvents` interface:
374+
Always define event types in the `EventBusEvents` interface for type safety:
346375

347376
```typescript
348377
export type EventBusEvents = {
@@ -357,7 +386,7 @@ export type EventBusEvents = {
357386
}
358387
```
359388
360-
### 3. Memory Management
389+
### 2. Memory Management
361390
362391
Always clean up event listeners to prevent memory leaks:
363392
@@ -385,7 +414,7 @@ onUnmounted(() => {
385414
</script>
386415
```
387416

388-
### 4. Error Handling
417+
### 3. Error Handling
389418

390419
Wrap event handlers in try-catch blocks:
391420

@@ -405,7 +434,7 @@ const handleDataUpdate = (data: any) => {
405434
}
406435
```
407436

408-
### 5. Debugging Events
437+
### 4. Debugging Events
409438

410439
Add logging for development:
411440

0 commit comments

Comments
 (0)