Skip to content

PengJiyuan/emitry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis npm npm codecov.io

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

npm i emitry

or

<script src="/path/emitry.umd.min.js"></script>
var emitry = new Emitry();

Usage

import Emitry from 'emitry';
const emitry = new Emitry();

Api

on(name, (value1, value2, ...) => {})

Subscribe to an event.

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.

emitry.once('oh', (value1, value2) => {
  console.log(value1, value2);
});

emit(name, value1, value2, ...)

Emit an event.

emitry.emit('oh', 'my god', 'my dear');  // 'mygod' 'my dear

off(name, callback)

Remove a listener from the listener array for the specified event.

emitry.off('oh', (value1, value2) => {
  console.log(value1, value2);
});

off([names])

Remove specify events by a list of names.

emitry.off(['a', 'b']);

off()

Remove all events.

emitry.off();

About

simple event emitter. (only 60 lines)

Resources

Stars

Watchers

Forks

Packages

No packages published