3.0.11 • Published 9 months ago

ste-simple-events v3.0.11

Weekly downloads
4,100
License
MIT
Repository
github
Last release
9 months ago

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.

3.0.11

9 months ago

3.0.9

1 year ago

3.0.8

1 year ago

3.0.7

1 year ago

3.0.6

2 years ago

3.0.4

2 years ago

3.0.5

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

2.1.16

2 years ago

2.1.14

2 years ago

2.1.13

3 years ago

2.1.12

3 years ago

2.1.11

3 years ago

2.1.10

3 years ago

2.1.9

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.5

3 years ago

2.1.2

3 years ago

2.0.9

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.6.22

4 years ago

1.6.20

4 years ago

1.6.21

4 years ago

1.6.19

4 years ago

1.6.17

4 years ago

1.6.16

4 years ago

1.6.15

4 years ago

1.6.14

4 years ago

1.6.13

4 years ago

1.6.12

4 years ago

1.6.9

4 years ago

1.6.11

4 years ago

1.6.10

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.4.11

5 years ago

1.4.10

5 years ago

1.4.8

5 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.3.13

6 years ago

1.3.12

6 years ago

1.3.11

6 years ago

1.3.10

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago