Created
June 1, 2016 14:00
-
-
Save sdtsui/e5a1b0f6d1896c6fcf61df2cfc8cbbe8 to your computer and use it in GitHub Desktop.
pubsub.js
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
// functional publish/subscribe | |
let Observers = []; | |
function subscribe(observer) { | |
Observers.push(observer); | |
} | |
function publish(event) { | |
Observers.forEach((observer) => { | |
observer(event); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment