mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
V2 (#1)
This commit is contained in:
21
packages/lib/src/events.js
Normal file
21
packages/lib/src/events.js
Normal file
@@ -0,0 +1,21 @@
|
||||
class Events {
|
||||
constructor() {
|
||||
this.listeners = [];
|
||||
}
|
||||
|
||||
listen(fn) {
|
||||
this.listeners.push(fn);
|
||||
}
|
||||
|
||||
unlisten(fn) {
|
||||
this.listeners = this.listeners(l => l !== fn);
|
||||
}
|
||||
|
||||
publish(type, data) {
|
||||
this.listeners.forEach(l => l(type, data));
|
||||
}
|
||||
}
|
||||
|
||||
const events = new Events();
|
||||
|
||||
export default events;
|
||||
Reference in New Issue
Block a user