source: trip-planner-front/node_modules/component-emitter/Readme.md@ eed0bf8

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

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1# Emitter [![Build Status](https://travis-ci.org/component/emitter.png)](https://travis-ci.org/component/emitter)
2
3 Event emitter component.
4
5## Installation
6
7```
8$ component install component/emitter
9```
10
11## API
12
13### Emitter(obj)
14
15 The `Emitter` may also be used as a mixin. For example
16 a "plain" object may become an emitter, or you may
17 extend an existing prototype.
18
19 As an `Emitter` instance:
20
21```js
22var Emitter = require('emitter');
23var emitter = new Emitter;
24emitter.emit('something');
25```
26
27 As a mixin:
28
29```js
30var Emitter = require('emitter');
31var user = { name: 'tobi' };
32Emitter(user);
33
34user.emit('im a user');
35```
36
37 As a prototype mixin:
38
39```js
40var Emitter = require('emitter');
41Emitter(User.prototype);
42```
43
44### Emitter#on(event, fn)
45
46 Register an `event` handler `fn`.
47
48### Emitter#once(event, fn)
49
50 Register a single-shot `event` handler `fn`,
51 removed immediately after it is invoked the
52 first time.
53
54### Emitter#off(event, fn)
55
56 * Pass `event` and `fn` to remove a listener.
57 * Pass `event` to remove all listeners on that event.
58 * Pass nothing to remove all listeners on all events.
59
60### Emitter#emit(event, ...)
61
62 Emit an `event` with variable option args.
63
64### Emitter#listeners(event)
65
66 Return an array of callbacks, or an empty array.
67
68### Emitter#hasListeners(event)
69
70 Check if this emitter has `event` handlers.
71
72## License
73
74MIT
Note: See TracBrowser for help on using the repository browser.