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

Event Registry System

Build an event registry that pre-registers event names to enable pattern-based event operations.

Context

Your application needs an event registry where event names are defined upfront. This allows using regular expression patterns to attach listeners and emit events to multiple related events at once (e.g., all events starting with "user.").

Requirements

Create a module that exports a createEventRegistry() function. The returned registry should:

  1. Allow registering a single event name
  2. Allow registering multiple event names from an array
  3. Support attaching listeners using regex patterns that match registered events
  4. Support emitting to multiple events using regex patterns

Test Cases

  • Registering a single event "app.started" allows adding a listener with regex pattern /app\..*/ that executes when "app.started" is emitted @test
  • Registering multiple events ["user.login", "user.logout", "user.register"] from an array allows a listener with pattern /user\..*/ to respond to all three @test
  • After registering "data.loaded", "data.saved", "data.deleted", emitting with pattern /data\..*/ triggers all listeners attached to these events @test

Implementation

@generates

API

/**
 * Creates and returns an event registry instance
 * @returns {Object} An event registry with registration methods
 */
function createEventRegistry() {
  // IMPLEMENTATION HERE
}

module.exports = { createEventRegistry };

Dependencies { .dependencies }

wolfy87-eventemitter { .dependency }

Provides event management functionality with support for event definition and pattern matching.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-wolfy87-eventemitter

tile.json