source: node_modules/eventemitter3/README.md

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.0 KB
Line 
1# EventEmitter3
2
3[![Version npm](https://img.shields.io/npm/v/eventemitter3.svg?style=flat-square)](https://www.npmjs.com/package/eventemitter3)[![CI](https://img.shields.io/github/actions/workflow/status/primus/eventemitter3/ci.yml?branch=master&label=CI&style=flat-square)](https://github.com/primus/eventemitter3/actions?query=workflow%3ACI+branch%3Amaster)[![Coverage Status](https://img.shields.io/coveralls/primus/eventemitter3/master.svg?style=flat-square)](https://coveralls.io/r/primus/eventemitter3?branch=master)
4
5EventEmitter3 is a high performance EventEmitter. It has been micro-optimized
6for various of code paths making this, one of, if not the fastest EventEmitter
7available for Node.js and browsers. The module is API compatible with the
8EventEmitter that ships by default with Node.js but there are some slight
9differences:
10
11- Domain support has been removed.
12- We do not `throw` an error when you emit an `error` event and nobody is
13 listening.
14- The `newListener` and `removeListener` events have been removed as they
15 are useful only in some uncommon use-cases.
16- The `setMaxListeners`, `getMaxListeners`, `prependListener` and
17 `prependOnceListener` methods are not available.
18- Support for custom context for events so there is no need to use `fn.bind`.
19- The `removeListener` method removes all matching listeners, not only the
20 first.
21
22It's a drop in replacement for existing EventEmitters, but just faster. Free
23performance, who wouldn't want that? The EventEmitter is written in EcmaScript 3
24so it will work in the oldest browsers and node versions that you need to
25support.
26
27## Installation
28
29```bash
30$ npm install --save eventemitter3
31```
32
33## CDN
34
35Recommended CDN:
36
37```text
38https://unpkg.com/eventemitter3@latest/dist/eventemitter3.umd.min.js
39```
40
41## Usage
42
43After installation the only thing you need to do is require the module:
44
45```js
46var EventEmitter = require('eventemitter3');
47```
48
49And you're ready to create your own EventEmitter instances. For the API
50documentation, please follow the official Node.js documentation:
51
52http://nodejs.org/api/events.html
53
54### Contextual emits
55
56We've upgraded the API of the `EventEmitter.on`, `EventEmitter.once` and
57`EventEmitter.removeListener` to accept an extra argument which is the `context`
58or `this` value that should be set for the emitted events. This means you no
59longer have the overhead of an event that required `fn.bind` in order to get a
60custom `this` value.
61
62```js
63var EE = new EventEmitter()
64 , context = { foo: 'bar' };
65
66function emitted() {
67 console.log(this === context); // true
68}
69
70EE.once('event-name', emitted, context);
71EE.on('another-event', emitted, context);
72EE.removeListener('another-event', emitted, context);
73```
74
75### Tests and benchmarks
76
77To run tests run `npm test`. To run the benchmarks run `npm run benchmark`.
78
79Tests and benchmarks are not included in the npm package. If you want to play
80with them you have to clone the GitHub repository. Note that you will have to
81run an additional `npm i` in the benchmarks folder before `npm run benchmark`.
82
83## License
84
85[MIT](LICENSE)
Note: See TracBrowser for help on using the repository browser.