1 |
|
2 | function DispatchEvents(thread){
|
3 | thread = (this.on = function(e, f, q){
|
4 | if (q = thread._on[e]) {
|
5 | q.push(f);
|
6 | } else {
|
7 | thread._on[e] = [f];
|
8 | }
|
9 | return thread;
|
10 | }, this.once = function(e, f, q){
|
11 | !(q = thread._on[e]) && (q = thread._on[e] = []);
|
12 | if (q.once) {
|
13 | q.once.push(f);
|
14 | } else {
|
15 | q.once = [f];
|
16 | }
|
17 | return thread;
|
18 | }, this.removeAllListeners = function(e){
|
19 | if (e) {
|
20 | delete thread._on[e];
|
21 | } else {
|
22 | thread._on = {};
|
23 | }
|
24 | return thread;
|
25 | }, this.dispatchEvents = function(event, args, q, i, len){
|
26 | var e, results$ = [];
|
27 | if (q = thread._on[event]) {
|
28 | try {
|
29 | i = 0;
|
30 | len = q.length;
|
31 | while (i < len) {
|
32 | q[i++].apply(thread, args);
|
33 | }
|
34 | if (q = q.once) {
|
35 | q.once = undefined;
|
36 | i = 0;
|
37 | len = q.length;
|
38 | while (i < len) {
|
39 | results$.push(q[i++].apply(thread, args));
|
40 | }
|
41 | return results$;
|
42 | }
|
43 | } catch (e$) {
|
44 | e = e$;
|
45 | return __postError({
|
46 | message: e,
|
47 | filename: '',
|
48 | lineno: 0
|
49 | });
|
50 | }
|
51 | }
|
52 | }, this._on = {}, this);
|
53 | return this.dispatchEvents;
|
54 | }
|