An open API service indexing awesome lists of open source software.

https://github.com/skrivle/tukio

Tukio is a minimal Pub-Sub implementation using class based events.
https://github.com/skrivle/tukio

event-emitter events javascript nodejs pubsub typescript

Last synced: about 1 month ago
JSON representation

Tukio is a minimal Pub-Sub implementation using class based events.

Awesome Lists containing this project

README

        

# Tukio

Tukio is a minimal Pub-Sub implementation using class based events.

## Why

Most of the javascript Pub-Sub implementations use string based events, which makes it impossible
for static type analysers like Typescript to infer the shape of an event inside an event handler. Tukio
resolves this by using class based events.

## Installation:

```
npm install tukio --save
```

## Usage:

```typescript
import EventBus from 'tukio';

const eventBus = new EventBus();

class TodoNameUpdated {
name: string;
constructor(name: string) {
this.name = name;
}
}

eventBus.subscribe(TodoNameUpdated, (event) => {
// Typescript can infer that event has a property name
console.log(event.name);
});

eventBus.publish(new TodoNameUpdated('new name'));
```