You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

ste-simple-events

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ste-simple-events

Add the power of Simple Events to your projects. Every event has an argument with its data.

3.0.11
latest
Source
npm
Version published
Weekly downloads
11K
28.18%
Maintainers
1
Weekly downloads
 
Created
Source

Strongly Typed Events - Simple events

Simple events are a type of event that will provide an argument with data when fired. 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 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 { SimpleEventDispatcher } from "ste-simple-events";

class Clock {
  private _onSequenceTick = new SimpleEventDispatcher<number>();
  private _ticks: number = 0;

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

  public get onSequenceTick() {
    return this._onSequenceTick.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.

Keywords

signals

FAQs

Package last updated on 09 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts