-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initialize background events (#280)
* Background Events POC * Storage should not extend EventEmitter * Update BackgroundEvents methods generic * Do not emit storage event (for now)
- Loading branch information
1 parent
36b2345
commit c60692d
Showing
4 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { EventEmitter } from 'events' | ||
|
||
interface BackgroundEvents { | ||
'storage.rate_of_pay_update': { | ||
rate: string | ||
} | ||
} | ||
|
||
export class EventsService extends EventEmitter { | ||
constructor() { | ||
super() | ||
} | ||
|
||
on<TEvent extends keyof BackgroundEvents>( | ||
eventName: TEvent, | ||
listener: (param: BackgroundEvents[TEvent]) => void | ||
): this { | ||
return super.on(eventName, listener) | ||
} | ||
|
||
once<TEvent extends keyof BackgroundEvents>( | ||
eventName: TEvent, | ||
listener: (param: BackgroundEvents[TEvent]) => void | ||
): this { | ||
return super.once(eventName, listener) | ||
} | ||
|
||
emit<TEvent extends keyof BackgroundEvents>( | ||
eventName: TEvent, | ||
...rest: undefined extends BackgroundEvents[TEvent] | ||
? [param?: BackgroundEvents[TEvent]] | ||
: [param: BackgroundEvents[TEvent]] | ||
): boolean { | ||
return super.emit(eventName, ...rest) | ||
} | ||
|
||
/** | ||
* Use `on` instead of `addListener` | ||
* @deprecated | ||
*/ | ||
addListener(): this { | ||
throw new Error('Use `on` instead of `addListner`.') | ||
} | ||
|
||
/** | ||
* Use `off` instead of `removeListener` | ||
* @deprecated | ||
*/ | ||
removeListener(): this { | ||
throw new Error('Use `off` instead of `removeListener`.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters