You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Sync in background for RN
This commit is contained in:
35
ReactNativeClient/lib/event-dispatcher.js
Normal file
35
ReactNativeClient/lib/event-dispatcher.js
Normal file
@ -0,0 +1,35 @@
|
||||
class EventDispatcher {
|
||||
|
||||
constructor() {
|
||||
this.listeners_ = [];
|
||||
}
|
||||
|
||||
dispatch(eventName, event = null) {
|
||||
if (!this.listeners_[eventName]) return;
|
||||
|
||||
let ls = this.listeners_[eventName];
|
||||
for (let i = 0; i < ls.length; i++) {
|
||||
ls[i](event);
|
||||
}
|
||||
}
|
||||
|
||||
on(eventName, callback) {
|
||||
if (!this.listeners_[eventName]) this.listeners_[eventName] = [];
|
||||
this.listeners_[eventName].push(callback);
|
||||
}
|
||||
|
||||
off(eventName, callback) {
|
||||
if (!this.listeners_[eventName]) return;
|
||||
|
||||
let ls = this.listeners_[eventName];
|
||||
for (let i = 0; i < ls.length; i++) {
|
||||
if (ls[i] === callback) {
|
||||
ls.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { EventDispatcher };
|
Reference in New Issue
Block a user