Skip to content

Instantly share code, notes, and snippets.

Last active June 3, 2020 16:01
What would you like to do?
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