Last active
November 21, 2020 00:32
-
-
Save intojs/0c8e69c02d52ba5ac09a1d1ede42cbcc to your computer and use it in GitHub Desktop.
React MVC - Subject
This file contains 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 Subject { | |
#observers = new Set(); | |
attach(observer) { | |
this.#observers.add(observer); | |
this.#notify(); | |
} | |
detach(observer) { | |
this.#observers.delete(observer); | |
} | |
#notify = () => { | |
this.#observers.forEach((observer) => { | |
observer.update(this); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment