Skip to content

Instantly share code, notes, and snippets.

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 pfftdammitchris/f1cd325287aed2f184f3041cd7675e5e to your computer and use it in GitHub Desktop.
Save pfftdammitchris/f1cd325287aed2f184f3041cd7675e5e to your computer and use it in GitHub Desktop.
// Private object hidden within this scope
let commands = {}
export function registerCommand(name, callback) {
if (commands[name]) commands[name].push(callback)
else commands[name] = [callback]
}
export function dispatch(name, action) {
commands[name]?.forEach?.((fn) => fn?.(action))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment