Created
November 27, 2018 15:55
-
-
Save nishanbajracharya/991386ce21d2a762ca474602c6022736 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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