Created
June 12, 2021 09:33
-
-
Save devrkd/dbc2064ea4af0d31bcd7c90831b88788 to your computer and use it in GitHub Desktop.
Sample subs and unsubs code
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
const score = new Score(); | |
const display = new DisplayScore(); | |
const cli = new CliScore(); | |
score.subscribe(display); | |
score.subscribe(cli); | |
score.updateScore(4); | |
score.unsubscribe(cli); | |
score.updateScore(5); | |
score.unsubscribe(display); | |
score.updateScore(6); | |
//The above will output | |
/* | |
got new score..... | |
Display score: 4 | |
CLI score: 4 | |
observer detached...CliScore | |
got new score..... | |
Display score: 5 | |
observer detached...DisplayScore | |
got new score..... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment