emitry

2019-11-22 admin

emitry是什么

什么是emitry,Event emit and catch

emitry使用教程帮助文档

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

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-79651.html

文章标题:emitry

回到顶部