Websocket
[VSoRC/.git] / node_modules / websocket / node_modules / yaeti / README.md
1 # yaeti
2
3 Yet Another [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) Implementation.
4
5 The library exposes both the [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) interface and the [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) interface.
6
7
8 ## Installation
9
10 ```bash
11 $ npm install yaeti --save
12 ```
13
14
15 ## Usage
16
17 ```javascript
18 var yaeti = require('yaeti');
19
20
21 // Custom class we want to make an EventTarget.
22 function Foo() {
23     // Make Foo an EventTarget.
24     yaeti.EventTarget.call(this);
25 }
26
27 // Create an instance.
28 var foo = new Foo();
29
30 function listener1() {
31     console.log('listener1');
32 }
33
34 function listener2() {
35     console.log('listener2');
36 }
37  
38 foo.addEventListener('bar', listener1);
39 foo.addEventListener('bar', listener2);
40 foo.removeEventListener('bar', listener1);
41
42 var event = new yaeti.Event('bar');
43
44 foo.dispatchEvent(event);
45
46
47 // Output:
48 // => "listener2"
49 ```
50
51
52
53 ## API
54
55
56 #### `yaeti.EventTarget` interface
57
58 Implementation of the [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) interface.
59
60 * Make a custom class inherit from `EventTarget`:
61 ```javascript
62 function Foo() {
63     yaeti.EventTarget.call(this);
64 }
65 ```
66
67 * Make an existing object an `EventTarget`:
68 ```javascript
69 yaeti.EventTarget.call(obj);
70 ```
71
72 The interface implements the `addEventListener`, `removeEventListener` and `dispatchEvent` methods as defined by the W3C.
73
74
75 ##### `listeners` read-only property
76
77 Returns an object whose keys are configured event types (String) and whose values are an array of listeners (functions) for those event types.
78
79
80 #### `yaeti.Event` interface
81
82 Implementation of the [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) interface.
83
84 *NOTE:* Just useful in Node (the browser already exposes the native `Event` interface).
85
86 ```javascript
87 var event = new yaeti.Event('bar');
88 ```
89
90
91 ## Author
92
93 [IƱaki Baz Castillo](https://github.com/ibc)
94
95
96 ## License
97
98 [MIT](./LICENSE)