Skip to content
A tidy alternative to EventEmitter.
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.
src
.gitignore
.npmignore
LICENSE
README.md
package.json
tsconfig.json

README.md

Eventual

Eventual is a compositional alternative to EventEmitter.

In contrast with EventEmitter, Eventual removes the need to inherit or wrap an EventEmitter and instead handles events at the variable or property level.

Installation

NPM: npm install --save @reasonink/eventual

Yarn: yarn add @reasonink/eventual

How it works

Create an Eventual instance using the eventual() factory function.

let loaded = eventual();

Add handlers with on(callback) or once(callback).

loaded.on(e => console.log(`Data loaded: ${e.data}`));

Fire the event with fire(event).

loaded.fire({ data: "the data" });

Callbacks can be removed with off().

function myHandler() {
    // Do something
}

loaded.on(myHandler);

// ...

loaded.off(myHandler);

Type safety

Eventual is built with (but doesn't require) TypeScript. Event types can be specified as a type argument to eventual<T>(). Callbacks will expect the given type as their only argument.

Example

interface DataEvent {
    data: string;
}

let loaded = eventual<DataEvent>();
loaded.on((e: DataEvent) => {
    // Do something with e
});
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.