source: trip-planner-front/node_modules/eventemitter3/README.md@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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