Event System
The Event System in Matrix Framework handles the propagation and processing of events through the middleware tree.
Overview
Events can flow through the tree in different ways:
- Bubble up from child to parent
- Tunnel down from parent to child
- Direct routing to specific nodes
Key Features
- Event Types: Support for different event types and priorities
- Routing Strategies: Flexible routing through the tree
- Event Context: Rich context object passed with events
- Async Processing: Full support for async event handlers
Example
// Define an event handler
element.on("message", async (ctx, next) => {
console.log("Processing message");
await next();
});
// Route an event
await element.routeEvent(new MiddlewareEvent("message"));