/
app.manager.events.ts
34 lines (32 loc) · 1.07 KB
/
app.manager.events.ts
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
import EventEmitter from "events";
import { AppEvents } from "managers";
export const getAppManagerEvents = (emitter: EventEmitter) => ({
emitFocus: (): void => {
emitter.emit(AppEvents.focus);
},
emitBlur: (): void => {
emitter.emit(AppEvents.blur);
},
emitOnline: (): void => {
emitter.emit(AppEvents.online);
},
emitOffline: (): void => {
emitter.emit(AppEvents.offline);
},
onFocus: (callback: () => void): VoidFunction => {
emitter.on(AppEvents.focus, callback);
return () => emitter.removeListener(AppEvents.focus, callback);
},
onBlur: (callback: () => void): VoidFunction => {
emitter.on(AppEvents.blur, callback);
return () => emitter.removeListener(AppEvents.blur, callback);
},
onOnline: (callback: () => void): VoidFunction => {
emitter.on(AppEvents.online, callback);
return () => emitter.removeListener(AppEvents.online, callback);
},
onOffline: (callback: () => void): VoidFunction => {
emitter.on(AppEvents.offline, callback);
return () => emitter.removeListener(AppEvents.offline, callback);
},
});