Skip to content

Instantly share code, notes, and snippets.

@shalvah
Last active January 9, 2019 19:39
Show Gist options
  • Save shalvah/c39e74b29aefc4f18ce661c9c1543d51 to your computer and use it in GitHub Desktop.
Save shalvah/c39e74b29aefc4f18ce661c9c1543d51 to your computer and use it in GitHub Desktop.
// the base command class or interface
class Command {
handle() {
}
}
class CreateUserCommand extends Command {
constructor(user) {
super();
this.user = user;
}
handle() {
// create the user in the db
}
}
const createUser = new CreateUserCommand(user);
// dispatch the command - this calls the handle() method
dispatch(createUser);
// or you could use a CommandHandler class
commandHandler.handle(createUser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment