-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.js
More file actions
23 lines (22 loc) · 697 Bytes
/
event.js
File metadata and controls
23 lines (22 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module.exports = event
function event() {
const listeners = []
return {
_listeners: listeners,
addListener: (l => {
const found = listeners.find(l2 => l === l2)
if (found === undefined)
listeners.push(l)
else
console.log(`listener already in event: ${l}`);
}),
removeListener: (l => {
const found = listeners.find(l2 => l === l2)
if (found !== undefined)
listeners.splice(listeners.indexOf(l), 1)
else
console.log(`listener not found: ${l}`);
}),
invoke: (args => listeners.forEach(l => l(args)))
}
}