Skip to content

Instantly share code, notes, and snippets.

@richartkeil
Created July 15, 2020 22:50
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/71b1919a2ada2f70e0af9c47145ab0d1 to your computer and use it in GitHub Desktop.
Save richartkeil/71b1919a2ada2f70e0af9c47145ab0d1 to your computer and use it in GitHub Desktop.
interface Broadcaster {
send(event: Event, user: User)
}
class EmailBroadcaster implements Broadcaster {
send(event: Event, user: User) {
const description = `New event ${event.name} occured at ${event.getTimestamp()}`
emailService.send({ to: user.email, subject: event.name, body: description })
}
}
class NotificationHandler {
constructor(private broadcaster: Broadcaster) {}
broadcast(event: Event, user: User) {
this.broadcaster.send(event, user)
}
}
function onAccountCreated(event: Event, user: User) {
const notifications = new NotificationHandler(new EmailBroadcaster())
notifications.broadcast(event, user)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment