Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Last active April 5, 2019 12:56
Show Gist options
  • Save SethVandebrooke/b0d45a7dcaa9e186487dc8245bcff1ee to your computer and use it in GitHub Desktop.
Save SethVandebrooke/b0d45a7dcaa9e186487dc8245bcff1ee to your computer and use it in GitHub Desktop.
A super simple pubsub utilizing javascript sets
function TinyPS() {
var listeners = new Set();
return {
pub: (...args) => Array.from(listeners).forEach(listener => listener(...args)),
sub: listener => listeners.add(listener) && listener,
unsub: listener => listeners.delete(listener),
wipe: () => listeners.clear()
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment