CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-wolfy87-eventemitter

Event based JavaScript for the browser with comprehensive event management API

91

1.26x
Overview
Eval results
Files

task.mdevals/scenario-3/

Event Subscription Manager

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.

Requirements

Create a notification subscription manager with the following features:

  1. Subscribe to Events: Users should be able to register callback functions for specific event types (e.g., "newsletter", "alerts", "promotions")

  2. Unsubscribe from Events: Users should be able to remove specific callback functions from event types they no longer want to receive

  3. Duplicate Prevention: The same callback function should not be registered multiple times for the same event type

  4. Method Chaining: Subscription and unsubscription operations should support chaining to allow fluent API usage

  5. Validation: The system should validate that subscriptions are registered with proper callback functions (not other data types)

Implementation

@generates

API

/**
 * Creates and returns a subscription manager instance
 */
function createSubscriptionManager();

Test Cases

  • 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

Dependencies { .dependencies }

wolfy87-eventemitter { .dependency }

Provides event management capabilities including listener registration, removal, and duplicate prevention.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-wolfy87-eventemitter

tile.json