7.8 KiB
7.8 KiB
Events Package Gap Analysis
Overview
This document analyzes the gaps between our Events package's actual implementation and our documentation, identifying areas that need implementation or documentation updates.
Related Documentation
- See Events Package Specification for current implementation
- See Laravel Compatibility Roadmap for overall status
- See Foundation Integration Guide for integration patterns
- See Testing Guide for testing approaches
- See Getting Started Guide for development setup
Implementation Gaps
1. Missing Laravel Features
// Documented but not implemented:
// 1. Event Discovery
class EventDiscovery {
// Need to implement:
Map<Type, Function> discoverHandlers(Type type);
void discoverEvents(String path);
}
// 2. After Commit Handling
class DatabaseEventDispatcher {
// Need to implement:
Future<void> dispatchAfterCommit<T>(T event);
void afterCommit(Function callback);
}
// 3. Better Broadcasting
class BroadcastManager {
// Need to implement:
Channel privateChannel(String name);
PresenceChannel presenceChannel(String name);
Future<void> broadcast(List<String> channels, String event, dynamic data);
}
2. Existing Features Not Documented
// Implemented but not documented:
// 1. Wildcard Event Listeners
class Dispatcher {
/// Adds wildcard event listener
void _setupWildcardListen(String event, Function listener) {
_wildcards.putIfAbsent(event, () => []).add(listener);
_wildcardsCache.clear();
}
/// Gets wildcard listeners
List<Function> _getWildcardListeners(String eventName);
}
// 2. Event Bus Integration
class Dispatcher {
/// EventBus integration
final EventBus _eventBus;
final Map<String, StreamSubscription> _eventBusSubscriptions = {};
/// Subscribes to EventBus
void subscribe(EventBusSubscriber subscriber);
}
// 3. Message Queue Integration
class Dispatcher {
/// MQ integration
late final MQClient? _mqClient;
/// Queue setup
void _setupQueuesAndExchanges();
void _startProcessingQueuedEvents();
}
3. Integration Points Not Documented
// 1. Container Integration
class Dispatcher {
/// Container reference
final Container container;
/// Queue resolver
late final Function _queueResolver;
/// Transaction manager resolver
late final Function _transactionManagerResolver;
}
// 2. ReactiveX Integration
class Dispatcher {
/// Subject management
final Map<String, BehaviorSubject<dynamic>> _subjects = {};
/// Stream access
Stream<T> on<T>(String event);
}
// 3. Resource Management
class Dispatcher {
/// Cleanup
Future<void> close();
void dispose();
}
Documentation Gaps
1. Missing API Documentation
// Need to document:
/// Listens for events using wildcard patterns.
///
/// Example:
/// ```dart
/// dispatcher.listen('user.*', (event, data) {
/// // Handles all user events
/// });
/// ```
void listen(String pattern, Function listener);
/// Subscribes to event streams using ReactiveX.
///
/// Example:
/// ```dart
/// dispatcher.on<UserCreated>('user.created')
/// .listen((event) {
/// // Handle user created event
/// });
/// ```
Stream<T> on<T>(String event);
2. Missing Integration Examples
// Need examples for:
// 1. EventBus Integration
var subscriber = MyEventSubscriber();
dispatcher.subscribe(subscriber);
// 2. Message Queue Integration
dispatcher.setMQClient(mqClient);
await dispatcher.push('user.created', userData);
// 3. ReactiveX Integration
dispatcher.on<UserEvent>('user.*')
.where((e) => e.type == 'premium')
.listen((e) => handlePremiumUser(e));
3. Missing Test Coverage
// Need tests for:
void main() {
group('Wildcard Events', () {
test('matches wildcard patterns', () {
var dispatcher = Dispatcher(container);
var received = <String>[];
dispatcher.listen('user.*', (event, _) {
received.add(event);
});
await dispatcher.dispatch('user.created');
await dispatcher.dispatch('user.updated');
expect(received, ['user.created', 'user.updated']);
});
});
group('Queue Integration', () {
test('queues events properly', () async {
var dispatcher = Dispatcher(container);
dispatcher.setMQClient(mockClient);
await dispatcher.push('delayed.event', data);
verify(() => mockClient.sendMessage(
exchangeName: any,
routingKey: any,
message: any
)).called(1);
});
});
}
Implementation Priority
-
High Priority
- Event discovery (Laravel compatibility)
- After commit handling (Laravel compatibility)
- Better broadcasting support
-
Medium Priority
- Better queue integration
- Enhanced wildcard support
- Performance optimizations
-
Low Priority
- Additional helper methods
- Extended testing utilities
- Debug/profiling tools
Next Steps
-
Implementation Tasks
- Add event discovery
- Add after commit handling
- Enhance broadcasting
- Improve queue integration
-
Documentation Tasks
- Document wildcard events
- Document EventBus integration
- Document MQ integration
- Add integration examples
-
Testing Tasks
- Add wildcard event tests
- Add queue integration tests
- Add ReactiveX integration tests
- Add resource cleanup tests
Would you like me to:
- Start implementing missing features?
- Update documentation for existing features?
- Create test cases for missing coverage?
Development Guidelines
1. Getting Started
Before implementing event features:
- Review Getting Started Guide
- Check Laravel Compatibility Roadmap
- Follow Testing Guide
- Use Foundation Integration Guide
- Review Events Package Specification
2. Implementation Process
For each event feature:
- Write tests following Testing Guide
- Implement following Laravel patterns
- Document following Getting Started Guide
- Integrate following Foundation Integration Guide
3. Quality Requirements
All implementations must:
- Pass all tests (see Testing Guide)
- Meet Laravel compatibility requirements
- Follow integration patterns (see Foundation Integration Guide)
- Match specifications in Events Package Specification
4. Integration Considerations
When implementing event features:
- Follow patterns in Foundation Integration Guide
- Ensure Laravel compatibility per Laravel Compatibility Roadmap
- Use testing approaches from Testing Guide
- Follow development setup in Getting Started Guide
5. Performance Guidelines
Events system must:
- Handle high event throughput
- Minimize memory usage
- Support async operations
- Scale horizontally
- Meet performance targets in Laravel Compatibility Roadmap
6. Testing Requirements
Event tests must:
- Cover all event scenarios
- Test async behavior
- Verify queue integration
- Check broadcasting
- Follow patterns in Testing Guide
7. Documentation Requirements
Event documentation must:
- Explain event patterns
- Show integration examples
- Cover error handling
- Include performance tips
- Follow standards in Getting Started Guide