https://github.com/pengjiyuan/emitry
simple event emitter. (only 60 lines)
https://github.com/pengjiyuan/emitry
Last synced: 4 months ago
JSON representation
simple event emitter. (only 60 lines)
- Host: GitHub
- URL: https://github.com/pengjiyuan/emitry
- Owner: PengJiyuan
- Created: 2018-05-17T04:02:43.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T09:08:08.000Z (almost 7 years ago)
- Last Synced: 2025-02-06T09:02:49.415Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/PengJiyuan/emitry)
[](https://www.npmjs.com/package/emitry)
[](https://www.npmjs.com/package/emitry)
[](https://codecov.io/github/PengJiyuan/emitry?branch=master)# emitry
simple event emitter.## Why emitry?
* **Small** - The source code is less than 100 lines. After minified and gzipped, only 450B.
* **Simple** - Only 4 api, but it can solve most of the scenes.
* **Cross platform** - It can work on nodejs, browser...## Install
```bash
npm i emitry
```or
```html
```
```javascript
var emitry = new Emitry();
```## Usage
```javascript
import Emitry from 'emitry';
const emitry = new Emitry();
```## Api
#### on(name, (value1, value2, ...) => {})
Subscribe to an event.
```javascript
emitry.on('oh', (value1, value2) => {
console.log(value1, value2);
});
```#### once(name, value1, value2, ...)
Subscribe to an event. Only trigger once, after triggered will remove from events list.
```javascript
emitry.once('oh', (value1, value2) => {
console.log(value1, value2);
});
```#### emit(name, value1, value2, ...)
Emit an event.
```javascript
emitry.emit('oh', 'my god', 'my dear'); // 'mygod' 'my dear
```#### off(name, callback)
Remove a listener from the listener array for the specified event.
```javascript
emitry.off('oh', (value1, value2) => {
console.log(value1, value2);
});
```#### off([names])
Remove specify events by a list of names.
```javascript
emitry.off(['a', 'b']);
```#### off()
Remove all events.
```javascript
emitry.off();
```