0.3.7 • Published 7 months ago

@twilio/replay-event-emitter v0.3.7

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

EventReplayEmitter

An extension to Node's EventEmitter that supports event replay. In other words, if a listener is added using either addListenerWithReplay or onWithReplay, then it will instantly trigger the listener with previous event data (if no data was previously emitted, then the listener will not get triggered on registration).

Usage Examples

In order to get event replay on listener registration, simply utilize the addListenerWithReplay method like so:

import { ReplayEventEmitter } from "replay-event-emitter";

// Instantiate the event emitter
const eventEmitter = new ReplayEventEmitter();

// Emit an event before adding a listener
eventEmitter.emit("exampleEvent", "someData");

// Subscribe using addListenerWithReplay
eventEmitter.addListenerWithReplay("exampleEvent", (data) => {
  // This handler will get triggered despite the data emission happening BEFORE
  // the event registration.
  console.log(data);
});

You could also use the shorthand method onWithRepeat, like so:

eventEmitter.onWithReplay("exampleEvent", (data) => {
  console.log(data);
});

All the original functionality of the EventEmitter is still intact:

import { ReplayEventEmitter } from "replay-event-emitter";

const eventEmitter = new ReplayEventEmitter();

eventEmitter.emit("exampleEvent", "someData");

eventEmitter.addListener("exampleEvent", (data) => {
  // This handler will NOT get triggered, as this is not a replay method and the
  // data emission happened BEFORE the event registration.
  console.log(data);
});
0.3.7-rc.0

9 months ago

0.3.6

11 months ago

0.3.7

7 months ago

0.3.6-rc.0

11 months ago

1.0.0-rc.5

12 months ago

1.0.0-rc.6

12 months ago

0.3.5

1 year ago

0.3.4-rc.1

1 year ago

0.3.4-rc.2

1 year ago

0.3.4

1 year ago

0.3.5-rc.0

1 year ago

0.3.4-rc.0

1 year ago

0.3.3

1 year ago

0.3.3-rc.3

1 year ago

0.3.3-rc.2

1 year ago

0.3.3-rc.4

1 year ago

1.0.0-rc.3

1 year ago

1.0.0-rc.4

1 year ago

0.3.2-rc.1

1 year ago

0.3.1-rc.1

2 years ago

0.3.1

2 years ago

0.3.0-rc.5

2 years ago

0.3.0-rc.3

2 years ago

0.3.0-rc.4

2 years ago

0.3.0-rc.2

2 years ago

0.3.0

2 years ago

0.3.0-rc.0

2 years ago

0.3.0-rc.1

2 years ago

0.3.0-canary.9

2 years ago

0.2.4

2 years ago

0.2.4-rc.0

2 years ago

0.2.3-rc.3

2 years ago

0.2.3-rc.4

2 years ago

0.2.3-rc.1

3 years ago

0.2.3-rc.2

2 years ago

0.2.3-canary.2

2 years ago

0.2.3-canary.1

2 years ago

0.2.3

2 years ago

0.2.3-rc.0

3 years ago

0.2.2-rc.7

3 years ago

0.2.2

3 years ago

0.2.2-rc.5

3 years ago

0.2.2-rc.3

3 years ago

0.2.2-rc.2

3 years ago

0.2.2-rc.1

3 years ago

0.2.2-rc.4

3 years ago

0.1.0-main.29

3 years ago

0.2.1

3 years ago

0.2.1-rc.0

3 years ago

0.2.0

3 years ago

0.2.0-rc.0

3 years ago

0.1.0-rc.1

3 years ago

0.1.0-rc.0

3 years ago

0.1.0

3 years ago

0.1.0-rc2

3 years ago

0.1.0-main.17

3 years ago

0.1.0-rc1

3 years ago

0.1.0-main.10

3 years ago

0.1.0-main.7

3 years ago

0.1.0-main.4

3 years ago