Created
November 14, 2022 07:29
-
-
Save pfftdammitchris/f1cd325287aed2f184f3041cd7675e5e 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