Skip to content

Instantly share code, notes, and snippets.

@pfftdammitchris
Created November 14, 2022 06:31
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/b84e21ac1a95fb0744a416b44af8e422 to your computer and use it in GitHub Desktop.
Save pfftdammitchris/b84e21ac1a95fb0744a416b44af8e422 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