Skip to content

Instantly share code, notes, and snippets.

@richartkeil
Created June 12, 2020 15:44
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/698c0f50df67215c0bec9c6ca84320ce to your computer and use it in GitHub Desktop.
Save richartkeil/698c0f50df67215c0bec9c6ca84320ce to your computer and use it in GitHub Desktop.
interface CanBroadcast {
send(event: Event, user: User)
}
interface CanTrackReads {
trackReads(track: boolean);
}
class EmailBroadcaster implements CanBroadcast, CanTrackReads {
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 })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment