Last active
May 4, 2018 01:00
-
-
Save aoberoi/01fbdab36ba6c2742081aec7216841ea to your computer and use it in GitHub Desktop.
This file contains 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
// define dispatch table OR import it from somewhere else | |
// const commands = require('./commands/live/somewhere'); | |
const commands = { | |
first: (foo, bar) => { /* ... */ }, | |
second: (baz) => { /* ... */ }, | |
help: (commandName) => { /* ... */ } | |
}; | |
function usingDispatch(commandName, ...args) { | |
const command = commands[commandName] || commands.help; | |
command(args); | |
doTheRest(); | |
} |
This file contains 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 doFirst(foo, bar) { /* ... */ } | |
function doSecond(baz) { /* ... */ } | |
function doHelp(commandName) { /* ... */ } | |
function usingSwitch(commandName, ...args) { | |
switch (commandName) { | |
case 'first': | |
doFirst(args); | |
break; | |
case 'second': | |
doSecond(args); | |
break; | |
default: | |
doHelp(args[0]); | |
break; | |
} | |
doTheRest(); // ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment