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