This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventEmitter.cs
67 lines (55 loc) · 2.35 KB
/
EventEmitter.cs
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
//TODO: object => Symbol
using Event = Bridge.Union<string, object>;
namespace Bridge.EventEmitter3
{
[External]
public abstract class EventEmitter
{
public delegate void ListenerFn(params object[] args);
public static extern Union<string, bool> Prefixed { get; set; }
/// <summary>
/// Return an array listing the events for which the emitter has registered listeners.
/// </summary>
public extern Event[] EventNames { [Template("eventNames()")] get; }
/// <summary>
/// Return the listeners registered for a given event.
/// </summary>
/// <param name="event">The event name.</param>
/// <param name="exists">Only check if there are listeners.</param>
public extern Union<ListenerFn[], bool> Listeners(Event @event, bool exists);
/// <summary>
/// Return the listeners registered for a given event.
/// </summary>
public extern ListenerFn[] Listeners(Event @event);
/// <summary>
/// Calls each of the listeners registered for a given event.
/// </summary>
public extern bool Emit(Event @event, params object[] args);
/// <summary>
/// Add a listener for a given event.
/// </summary>
public extern EventEmitter On(Event @event, ListenerFn fn, object context = null);
/// <summary>
/// Add a listener for a given event.
/// </summary>
public extern EventEmitter AddListener(Event @event, ListenerFn fn, object context = null);
/// <summary>
/// Add a one-time listener for a given event.
/// </summary>
public extern EventEmitter Once(Event @event, ListenerFn fn, object context = null);
/// <summary>
/// Remove the listeners of a given event.
/// </summary>
public extern EventEmitter Off(Event @event, ListenerFn fn,
object context = null, bool? once = null);
/// <summary>
/// Remove the listeners of a given event.
/// </summary>
public extern EventEmitter RemoveListener(Event @event, ListenerFn fn,
object context = null, bool? once = null);
/// <summary>
/// Remove all listeners, or those of the specified event.
/// </summary>
public extern EventEmitter RemoveAllListeners(Event @event);
}
}