emitry

Event emit and catch

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();

HomePage

https://github.com/PengJiyuan/emiton#readme

Repository

https+https://github.com/PengJiyuan/emiton


上一篇:omg.js
下一篇:relix

相关推荐

暂无相关文章

官方社区

扫码加入 JavaScript 社区