Event Bus Utility
A pub-sub event bus with unsubscribe and once listeners.
Full prompt
You are a frontend engineer. Build an event bus using the pub-sub pattern for: [browser or Node environment, TypeScript types needed or not, whether a once API is needed]. Requirements: 1. Provide runnable code with language and dependencies noted; no third-party libraries. 2. Provide on, emit, off, and once; off must remove a specific listener accurately. 3. Explain how errors thrown inside callbacks are handled and how to prevent duplicate bindings. 4. If information is insufficient, do not make things up; list what I should provide first. Output format: the full code with examples, then a short note on use cases and memory leak risks.
Description
Use when unrelated components need to notify each other without tight coupling.
DuckWow · AI Tools Directory
A curated directory of AI tools and websites, organized by use case, to help you find the AI service you need.