Event based JavaScript for the browser with comprehensive event management API
91
Build a simple event subscription system that allows users to subscribe and unsubscribe from different notification types. The system should manage event handlers, prevent duplicate subscriptions, and support method chaining for fluent API usage.
Create a notification subscription manager with the following features:
Subscribe to Events: Users should be able to register callback functions for specific event types (e.g., "newsletter", "alerts", "promotions")
Unsubscribe from Events: Users should be able to remove specific callback functions from event types they no longer want to receive
Duplicate Prevention: The same callback function should not be registered multiple times for the same event type
Method Chaining: Subscription and unsubscription operations should support chaining to allow fluent API usage
Validation: The system should validate that subscriptions are registered with proper callback functions (not other data types)
@generates
/**
* Creates and returns a subscription manager instance
*/
function createSubscriptionManager();When subscribing to "newsletter" with a callback function, that callback can be triggered when the newsletter event occurs @test
When subscribing the same callback function twice to the same event type, only one instance is stored (prevents duplicates) @test
When unsubscribing a specific callback from an event type, that callback is no longer triggered for that event @test
When chaining multiple subscribe operations, all callbacks are registered correctly @test
When attempting to subscribe with a non-function value (like a string or number), an appropriate error is thrown @test
Provides event management capabilities including listener registration, removal, and duplicate prevention.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-wolfy87-eventemitterdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10