Skip to content

Instantly share code, notes, and snippets.

@sdtsui
Created June 1, 2016 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdtsui/e5a1b0f6d1896c6fcf61df2cfc8cbbe8 to your computer and use it in GitHub Desktop.
Save sdtsui/e5a1b0f6d1896c6fcf61df2cfc8cbbe8 to your computer and use it in GitHub Desktop.
pubsub.js
// 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