Releases: Constantiner/zohar
Releases · Constantiner/zohar
v1.1.0
Added Helper Functions for Ergonomic Event Handling
Features
-
Added
subscriber
helper function to create specialized subscription functions- Type-safe event subscriptions with improved ergonomics
- Removes need to specify event name in listener functions
- Supports predicates for event filtering
- Returns unsubscribe function for cleanup
-
Added
emitter
helper function to create specialized emit functions- Type-safe event emission with improved ergonomics
- Removes need to specify event name when emitting events
- Maintains full type safety for event data
Types
- Added
SpecializedEventListener<Event, EventType>
for simplified event listeners - Added
EventSubscriber<Event, EventType>
for specialized subscription functions - Added
EventSubscriberFactory<Event>
for subscription function factories - Added
EventEmitter<Event, EventType>
for specialized emit functions - Added
EventEmitterFactory<Event>
for emit function factories
Tests
- Added comprehensive test suite for both helper functions
- Coverage includes:
- Basic functionality
- Type safety verification
- Predicate handling
- Complex event types with intersection types
- Unsubscription behavior
Documentation
- Added detailed documentation for both helper functions
- Included practical examples demonstrating:
- Component-specific event handling
- Module-specific event management
- Complex event types with intersection types
- Added benefits section highlighting:
- Type safety
- Ergonomic API
- Better IDE support
- Modular design
- Reusability
Breaking Changes
None. This is a backward-compatible feature addition.
Example Usage
type MyEvents = EventDescription<'userConnected', { userId: string }>
& EventDescription<'userDisconnected', { userId: string; reason: 'timeout' | 'manual' }>;
const [subscribe, emit] = createEventEmitter<MyEvents>();
// Create specialized functions
const createSubscriber = subscriber(subscribe);
const createEmitter = emitter(emit);
const onUserConnected = createSubscriber('userConnected');
const emitUserConnected = createEmitter('userConnected');
// Use with improved ergonomics
onUserConnected((data) => {
console.log(`User ${data.userId} connected`);
});
emitUserConnected({ userId: 'user123' });
v1.0.1
Full Changelog: v1.0.0...v1.0.1
v1.0.0
The first release
Full Changelog: v0.0.3...v1.0.0
v0.0.3
Full Changelog: https://github.com/Constantiner/zohar/commits/v0.0.3