-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
89 lines (83 loc) · 3.43 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>event dispatcher</title>
<style>
body {
background-color: #fff;
color: #000;
font-family: Helvetica, Arial;
font-size: 12px;
padding: 50px;
}
body > div {
margin-top: 30px;
padding: 20px 0;
width: 600px;
}
body > div,
footer {
border-top: 1px solid #000;
}
footer {
padding-top: 20px;
}
</style>
</head>
<body>
<h1>EventDispatcher <img src="https://img.shields.io/bundlephobia/minzip/@danehansen/event-dispatcher.svg" alt="npm bundle size (scoped)" /> <img src="https://img.shields.io/npm/dt/@danehansen/event-dispatcher.svg" alt="npm" /></h1>
<p><strong>Class</strong> : public class <a href="https://github.com/danehansen/EventDispatcher">EventDispatcher</a><br />
<strong>Inheritance</strong> : <a href="https://github.com/danehansen/EventDispatcher">EventDispatcher</a> > Object<br />
<strong>Subclasses</strong> : <a href="https://github.com/danehansen/Preloader">Preloader</a>, <a href="https://github.com/danehansen/Sprite">Sprite</a>, <a href="https://github.com/danehansen/Timer">Timer</a></p>
<p>The EventDispatcher class is the base class for all classes that dispatch events. It is totally ripped off from the AS3 EventDispatcher, but simplified. EventDispatcher can also be used without creating an instance like singleton emitter.</p>
<h2>Installation</h2>
<p><code>npm install --save @danehansen/event-dispatcher</code></p>
<h2>Usage</h2>
<p>As a module:</p>
<pre><code>import EventDispatcher from '@danehansen/event-dispatcher';
var eventDispatcher = new EventDispatcher();
eventDispatcher.addEventListener('event', onEvent);
eventDispatcher.dispatchEvent('event');
function onEvent(evt) {
console.log('hi!');
}
</code></pre>
<p>In your browser:</p>
<pre><code><script src='danehansen-EventDispatcher.min.js'></script>
<script>
var EventDispatcher = window.danehansen.EventDispatcher;
var eventDispatcher = new EventDispatcher();
eventDispatcher.addEventListener('event', onEvent);
eventDispatcher.dispatchEvent('event');
function onEvent(evt) {
console.log('hi!');
}
</script>
</code></pre>
<h2>Public Static Methods</h2>
<ul>
<li><strong>addEventListener</strong>(type:String, listener:Function)<br />
[static] Registers an event listener object with EventDispatcher so that it will dispatch notification of an event.</li>
<li><strong>dispatchEvent</strong>(type:String, …args:*)<br />
[static] Emits an event, and passes along any extra arguments to the registered listeners.</li>
<li><strong>removeEventListener</strong> (type:String, listener:Function)<br />
[static] Removes a listener from EventDispatcher.</li>
</ul>
<h2>Public Methods</h2>
<ul>
<li><strong>EventDispatcher</strong>(target:Object)<br />
Aggregates an instance of the EventDispatcher class.</li>
<li><strong>addEventListener</strong>(type:String, listener:Function)<br />
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.</li>
<li><strong>clearEventListeners</strong>()<br />
Clears all event listeners of the instance.</li>
<li><strong>dispatchEvent</strong>(type:String)<br />
Dispatches an event into the event flow.</li>
<li><strong>removeEventListener</strong> (type:String, listener:Function)<br />
Removes a listener from the EventDispatcher object.</li>
</ul>
<script></script>
</body>
</html>