Skip to content

Instantly share code, notes, and snippets.

@nishanbajracharya
Created November 27, 2018 15:55
Show Gist options
  • Save nishanbajracharya/991386ce21d2a762ca474602c6022736 to your computer and use it in GitHub Desktop.
Save nishanbajracharya/991386ce21d2a762ca474602c6022736 to your computer and use it in GitHub Desktop.
class Observer {
constructor(subject) {
subject.registerObserver(this);
this.subscribers = [];
}
subscribe(subscriber) {
this.subscribers.push(subscriber);
}
notify(data) {
this.subscribers.forEach(subscriber => subscriber(data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment