Last active
April 5, 2019 12:56
-
-
Save SethVandebrooke/b0d45a7dcaa9e186487dc8245bcff1ee to your computer and use it in GitHub Desktop.
A super simple pubsub utilizing javascript sets
This file contains hidden or 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
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