Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Maintain a dictionary mapping event names to arrays of callback functions. The on method pushes a callback and returns an unsubscribe function that filters it out. The emit method iterates over all callbacks for the given event and invokes each with the provided data.
The publish-subscribe pattern decouples event producers from consumers through a shared registry, and returning an unsubscribe closure from on() provides clean lifecycle management.
Updated Feb 2026