Skip to content

Instantly share code, notes, and snippets.

@zinevych
Created May 30, 2019
Embed
What would you like to do?
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