min-event
v1.3.0
Published
Basic Event Lib
Downloads
40
Readme
min-event
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][downloads-url] [![Dependency Status][david-image]][david-url] [npm-image]: https://img.shields.io/npm/v/min-event.svg?style=flat-square [npm-url]: https://npmjs.org/package/min-event [downloads-image]: http://img.shields.io/npm/dm/min-event.svg?style=flat-square [downloads-url]: https://npmjs.org/package/min-event [david-image]: http://img.shields.io/david/chunpu/min-event.svg?style=flat-square [david-url]: https://david-dm.org/chunpu/min-event
Basic Event Lib
Installation
npm i min-event
Usage
var Emitter = require('min-event')
var emitter = new Emitter
Basic event lib, if you are confused, see <example/events.js> just like the node.js style events based on min-event
Proto Api
on
Accept one function argument, return a object {handler: listener}
var event = emitter.on(listener)
off
Accept one function argument, remove events filtered by filter
emitter.off(filter)
// e.g.
emitter.off(function(event) {
return event.type = 'event-type'
})
emit
Accept two function arguments, filter events and run events
emitter.emit(filter, runner)
// e.g.
emiter.emit(function(event) {
return event.type = 'mytype'
}, function(event) {
event.handler() // run the handler, it is absent runner
})