Created
May 30, 2019 09:20
-
-
Save zinevych/5ee2cce44878b491074fdfaa22c7c2a1 to your computer and use it in GitHub Desktop.
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
function Click() { | |
this.handlers = []; // observers | |
} | |
Click.prototype = { | |
subscribe: (fn) => { | |
this.handlers.push(fn); | |
}, | |
unsubscribe: (fn) => { | |
this.handlers = this.handlers.filter(...); | |
}, | |
notify: (o, thisObj) => {...} | |
} | |
function run() { | |
const clickHandler = (item) => { | |
log.add("fired: " + item); | |
}; | |
let click = new Click(); | |
click.subscribe(clickHandler); | |
click.notify('event #1'); | |
click.unsubscribe(clickHandler); | |
click.notify('event #2'); | |
click.subscribe(clickHandler); | |
click.notify('event #3'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment