Skip to content
A NodeJS-like EventEmitter for Deno in Typescript.
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
lib
test
.eslintrc.js
.gitignore
.travis.yml
LICENSE
README.md
mod.ts
package-lock.json
package.json

README.md

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)

  • No runtime type checks (Deno / TypeScript support compile time checks)
  • Error handling may require some more work.
  • Does not implement deprecated methods

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.

You can’t perform that action at this time.