mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-15 21:33:23 +00:00
Add type-safe EventBus with generic event mapping
Implemented EventBus class with full TypeScript type inference:
- Generic type parameter TEvents for event name to payload mapping
- Type-safe on/once/off/emit methods with inferred data types
- Utility methods: clear, listenerCount, eventNames
- Complete JSDoc documentation with usage examples
Added core connection types:
- ConnectionIdentity, ConnectionState, ConnectionInterface
- QueueMessageOptions for message queuing
- Connection composite type
All types and classes exported from main index.
Example usage:
```typescript
interface MyEvents {
'user:connected': { userId: string; timestamp: number };
'message:received': string;
}
const bus = new EventBus<MyEvents>();
// TypeScript knows data is { userId: string; timestamp: number }
bus.on('user:connected', (data) => {
console.log(data.userId, data.timestamp);
});
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
24
src/types.ts
Normal file
24
src/types.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Core connection types
|
||||
*/
|
||||
|
||||
export interface ConnectionIdentity {
|
||||
id: string;
|
||||
hostUsername: string;
|
||||
}
|
||||
|
||||
export interface ConnectionState {
|
||||
state: 'connected' | 'disconnected' | 'connecting';
|
||||
lastActive: number;
|
||||
}
|
||||
|
||||
export interface QueueMessageOptions {
|
||||
expiresAt?: number;
|
||||
}
|
||||
|
||||
export interface ConnectionInterface {
|
||||
queueMessage(message: string | ArrayBuffer, options?: QueueMessageOptions): void;
|
||||
sendMessage(message: string | ArrayBuffer): void;
|
||||
}
|
||||
|
||||
export type Connection = ConnectionIdentity & ConnectionState & ConnectionInterface;
|
||||
Reference in New Issue
Block a user