Last active
August 20, 2019 03:40
-
-
Save drewdaemon/6fbabc40b99ade57816e3b7079616a16 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
const createObservable = () => { | |
let observers = []; | |
const subscribe = (observer) => { | |
observers.push(observer); | |
return () => { | |
observers = observers.filter(o => o !== observer); | |
}; | |
}; | |
const publish = (toPublish) => { | |
observers.forEach(observer => observer(toPublish)); | |
}; | |
return {subscribe, publish}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment