Skip to content

Instantly share code, notes, and snippets.

@intojs
Last active November 21, 2020 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intojs/0c8e69c02d52ba5ac09a1d1ede42cbcc to your computer and use it in GitHub Desktop.
Save intojs/0c8e69c02d52ba5ac09a1d1ede42cbcc to your computer and use it in GitHub Desktop.
React MVC - Subject
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