Created
June 12, 2020 15:43
-
-
Save richartkeil/bf0f3b2056316b0911459563fdaed345 to your computer and use it in GitHub Desktop.
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
interface CanBroadcast { | |
send(event: Event, user: User) | |
trackReads(track: boolean) | |
} | |
class EmailBroadcaster implements CanBroadcast { | |
send(event: Event, user: User) { | |
emailService.send({ to: user.email, subject: event.name }) | |
} | |
trackReads(track: boolean) { | |
emailService.setConfig({ trackOpens: track ? "always" : "never" }) | |
} | |
} | |
class PushBroadcaster implements CanBroadcast { | |
send(event: Event, user: User) { | |
const description = `New event ${event.name} occured!` | |
pushService.push({ token: user.pushKey, body: description }) | |
} | |
trackReads(track: boolean) { | |
throw new Error("PushBroadcaster does not support tracking reads."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment