https://github.com/maxhoffmann/emitter
Event emitter implementation using the “frozen closure” pattern as described by Douglas Crockford.
https://github.com/maxhoffmann/emitter
Last synced: about 1 year ago
JSON representation
Event emitter implementation using the “frozen closure” pattern as described by Douglas Crockford.
- Host: GitHub
- URL: https://github.com/maxhoffmann/emitter
- Owner: maxhoffmann
- License: mit
- Created: 2014-06-25T12:26:46.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-06-19T14:00:06.000Z (almost 6 years ago)
- Last Synced: 2025-02-24T21:16:14.062Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Emitter [![npm version][1]][2]
=======
Event emitter implementation using the “frozen closure” pattern as [described by Douglas Crockford](http://www.ustream.tv/recorded/46640057). Heavily inspired by [component/emitter](https://github.com/component/emitter).
Browser support: ES5 compatible browsers (IE9+)
Installation
------------
```bash
npm install maxhoffmann-emitter --save
```
Usage
-----
```js
var Emitter = require('maxhoffmann-emitter');
var emitter = Emitter();
emitter.on('eventName', listener);
emitter.once('eventName', listener); // only listen once
emitter.off('eventName', listener); // remove specific listener
emitter.off('eventName'); // remove all listeners of this event
emitter.off(); // remove all listeners
emitter.trigger('eventName', arg1, arg2…); // arguments are optional
emitter.hasListeners('eventName');
emitter.hasListeners(); // returns true if any listeners are added
```
__Note:__ This library is built with webpack to the UMD format. You can therefore use it with common.js and amd loaders or as a global variable.
Testing
-------
- `cd` into directory
- run `npm test`
Development
-----------
`npm run build` to create a minimized and UMD format compatible version of the source file.
LICENSE
-------
The MIT License
[1]: http://img.shields.io/npm/v/maxhoffmann-emitter.svg?style=flat
[2]: https://www.npmjs.org/package/maxhoffmann-emitter