Skip to content

Instantly share code, notes, and snippets.

@richartkeil
Last active June 3, 2020 16:01
Show Gist options
  • Save richartkeil/3e20c422bb804b8fb832f1e5bab4805b to your computer and use it in GitHub Desktop.
Save richartkeil/3e20c422bb804b8fb832f1e5bab4805b to your computer and use it in GitHub Desktop.
interface EmailBroadcaster {
broadcast(event: Event);
}
class AnonymousEmailBroadcaster implements EmailBroadcaster {
constructor(protected user: User) {}
broadcast(event: Event) {
// Send email with event details to user.
}
}
class SubscriptionEmailBroadcaster implements EmailBroadcaster {
constructor(protected user: SubscribedUser) {}
broadcast(event: Event) {
// Send email with subscription information
// and event details to user.
}
}
function onAccountCreated(event: Event) {
const user = getCurrentUser(); // returns type User or SubscribedUser
(new AnonymousEmailBroadcaster(user)).broadcast(event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment