Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/lucasliet/message-emitter

a simple event emitter with topic and subscriber to use internally in code for typescript
https://github.com/lucasliet/message-emitter

Last synced: about 18 hours ago
JSON representation

a simple event emitter with topic and subscriber to use internally in code for typescript

Awesome Lists containing this project

README

        

# Message Emitter
Execute functions estimulated by events.

## installation
```SH
yarn add message-emitter
```

## usage

```TS
import * as Emitter from 'message-emitter';

Emitter.publish('test', 1, 2, 3 ,4 ); // pulish to topic 'test' the args 1, 2, 3, 4

Emitter.subscribe('test', args => console.log(args)); // if the topic was published execute callback function to given arguments

Emitter.deleteTopic('test'); // remove topic

Emitter.hasTopic('test'); // returns true if topic exists, otherwise false
```

> ℹ for JavaScript <= es5 use require
```JS
var Emitter = require('message-emitter');
Emitter.publish('test', 1, 2, 3 ,4 );
```