event_emitter Build Status

A NodeJS-like EventEmitter for Deno written in 100% Typescript.

Usage

Basic

import EventEmitter from "https://deno.land/x/event_emitter/mod.ts";

const emitter = new EventEmitter();

emitter.on("SayHello", (to: string) => {
  if (!to) {
    console.log("hello!");
  } else {
    console.log("hello" + to + "!");
  }
});

emitter.emit("SayHello");
// hello!
emitter.emit("SayHello", " world");
// hello world!
emitter.emit("SayHello", ", again, world");
// hello, again, world!

Extend EventEmitter Class

import EventEmitter from 'https://deno.land/x/event_emitter/mod.ts';

class NewClass extends EventEmitter {
  public constructor() {
    super();
  }

  public createEvent(): NewClass {
    this.emit('event', 'The createEvent() method was called');
    return this; // Chainable
  }
}

const instance: NewClass = new NewClass();
instance.on('event', (message: string): void => {
  console.log(`Message received: ${message}`);
});
instance.createEvent();
// Message received: The createEvent() method was called

Documentation

API

Dependencies

None!

Permissions

None!

Differences (between this and NodeJS version)

Licensing

Licensed under the permissive MIT license. See LICENCE file for more information

This project is based on the open source DenoLibs / deno_template template.


View repository on GitHub