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-2/

Event Notification System

Build a simple notification dispatcher that manages and triggers notifications for a user dashboard.

Requirements

Create a notification system that:

  1. Allows subscribing to different notification types (e.g., "info", "warning", "error")
  2. Can trigger notifications with relevant message data
  3. Supports passing multiple pieces of information when triggering a notification (message text, timestamp, priority level)
  4. Executes all subscribed handlers when a notification is triggered

Implementation

Implement a NotificationDispatcher class with the following capabilities:

  • Subscribe handlers to notification types
  • Trigger notifications with message data
  • Support multiple arguments when triggering notifications
  • Ensure handlers receive the data in the correct format

Test Cases

  • Triggering an "info" notification with message "System updated" executes the subscribed handler with that message @test
  • Triggering a "warning" notification with message "Low disk space", timestamp 1234567890, and priority 2 passes all three arguments to the handler @test
  • Triggering a notification type with multiple subscribed handlers executes all handlers in the order they were added @test
  • Triggering a notification type with no subscribed handlers completes without errors @test

API

class NotificationDispatcher {
  /**
   * Subscribe a handler function to a notification type
   * @param {string} type - The notification type (e.g., "info", "warning", "error")
   * @param {Function} handler - The function to call when this notification type is triggered
   */
  subscribe(type, handler) {
    // Implementation here
  }

  /**
   * Trigger a notification of a specific type with data
   * @param {string} type - The notification type to trigger
   * @param {...*} args - Arguments to pass to the handlers
   */
  notify(type, ...args) {
    // Implementation here
  }
}

module.exports = { NotificationDispatcher };

Dependencies { .dependencies }

wolfy87-eventemitter { .dependency }

Provides event management capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-wolfy87-eventemitter

tile.json