Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zaubernerd/tiny-events
A small and lightweight EventEmitter
https://github.com/zaubernerd/tiny-events
Last synced: 21 days ago
JSON representation
A small and lightweight EventEmitter
- Host: GitHub
- URL: https://github.com/zaubernerd/tiny-events
- Owner: ZauberNerd
- License: mit
- Created: 2014-10-21T21:22:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-12T17:18:50.000Z (almost 10 years ago)
- Last Synced: 2024-10-05T14:43:42.492Z (about 1 month ago)
- Language: JavaScript
- Size: 207 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-events [![Build Status][0]][1] [![Coverage Status][2]][3]
[![Sauce Test Status][4]][5]A very tiny (*400b*) EventEmitter implementation for client- and server-side code.
## installation
`npm install --save tiny-events`## usage
instantiate the object directly..```javascript
// import the module
var EventEmitter = require('tiny-events').EventEmitter;// instantiate the object
var events = new EventEmitter();// listen to 'foo' events
events.on('foo', function (data) {
console.log('foo occured!');
});// emit a 'foo' event
events.emit('foo');// emit a 'foo' event with some data
events.emit('foo', 'hello world');// remove all foo event listeners
events.off('foo');
```... or subclass it.
```javascript
var utils = require('utils');
var EventEmitter = require('tiny-events').EventEmitter;function MyClass() {
EventEmitter.call(this);
}util.inherits(MyClass, EventEmitter);
```## API
- `on(type: string, listener: Function): EventEmitter`
- `once(type: string, listener: Function): EventEmitter`
- `off(type: string, listener?: Function): EventEmitter`
- `emit(type: string, ...args: any[]): EventEmitter`[0]: https://img.shields.io/travis/ZauberNerd/tiny-events.svg
[1]: https://travis-ci.org/ZauberNerd/tiny-events
[2]: https://img.shields.io/coveralls/ZauberNerd/tiny-events.svg
[3]: https://coveralls.io/r/ZauberNerd/tiny-events?branch=master
[4]: https://saucelabs.com/browser-matrix/dom2wg-eventemitter.svg
[5]: https://saucelabs.com/u/dom2wg-eventemitter