Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including ste-events with all npm packages installed. Try it out:

var steEvents = require("ste-events")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ste-events v1.6.19

Add the power of Events to your projects. They are styled after .Net using a sender and arguments.

Strongly Typed Events - Events

Add events that are modeled after .Net with a sender and argument to your project. If you use typescript, you can leverage the support for generics and get strongly typed code.

Need a different type of event? Check out the others.

Build Status npm version forever code style: prettier License: MIT

Subscription made easy

An example says more than a 1000 words. Imagine if you have events like this on your class:

let clock = new Clock("Smu", 1000);

//log the name of the clock and the tick argument to the console - this is an event
clock.onClockTick.subscribe((c, n) =>
  console.log(`${c.name} ticked ${n} times.`)
);

Events made easy

So let's look at the implementation from a TypeScript perspective. (Do you program NodeJs without typescript? Check this)

import { EventDispatcher } from "ste-events";

class Clock {
  private _onClockTick = new EventDispatcher();
  private _ticks: number = 0;

  constructor(public name: string, timeout: number) {
    setInterval(() => {
      this._ticks += 1;
      this._onClockTick.dispatch(this, this._ticks);
    }, timeout);
  }

  public get onClockTick() {
    return this._onClockTick.asEvent();
  }
}

Check the documentation or the examples for more information.

Need more info? Check the repo.

Maintenance

This project is maintained by Kees C. Bakker.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free