You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document decorator-based event handler pattern for custom visualizers
- Add section on EventHandlerMixin and @Handles decorator
- Show how to avoid long if/elif chains in on_event methods
- Explain benefits: self-documenting, type-safe, extensible
- Provide complete working example with best practices
Co-authored-by: openhands <[email protected]>
-**Self-documenting code**: `@handles(ActionEvent)` clearly shows what each method does
571
+
-**Type safety**: The decorator enforces the event type relationship
572
+
-**Easy extensibility**: Add new event types without touching dispatch logic
573
+
-**No boilerplate**: No need to maintain separate dictionaries or long if/elif chains
574
+
575
+
### 4. Error Handling
524
576
Always include error handling to prevent visualization issues from breaking conversations:
525
577
526
578
```python
@@ -535,7 +587,7 @@ def on_event(self, event):
535
587
logging.warning(f"Visualizer failed: {e}")
536
588
```
537
589
538
-
### 3. Performance Considerations
590
+
### 5. Performance Considerations
539
591
For high-frequency events, consider optimizing your visualization by filtering events or using efficient output methods like `flush=True` for immediate display.
0 commit comments