Skip to content

Instantly share code, notes, and snippets.

@richartkeil
Created July 15, 2020 22:49
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/d40876a8abf1532cfd52c132923712fc to your computer and use it in GitHub Desktop.
Save richartkeil/d40876a8abf1532cfd52c132923712fc to your computer and use it in GitHub Desktop.
class EmailBroadcaster {
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 {
private mailer: EmailBroadcaster
constructor() {
this.mailer = new EmailBroadcaster()
}
public broadcast(event: Event, user: User) {
this.mailer.send(event, user)
}
}
function onAccountCreated(event: Event, user: User) {
const notifications = new NotificationHandler()
notifications.broadcast(event, user)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment