Skip to content

Instantly share code, notes, and snippets.

@richartkeil
Created June 12, 2020 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richartkeil/bf0f3b2056316b0911459563fdaed345 to your computer and use it in GitHub Desktop.
Save richartkeil/bf0f3b2056316b0911459563fdaed345 to your computer and use it in GitHub Desktop.
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