Dispatch reusable commands synchronously or asynchronously.
meteor add capsulecat:commands
The command pattern is a great way to encapsulate actions into an object. When working with Meteor (or almost any programming framework), you will find that you will want to do the same action over and over, but with some minor changes in the request or response. The Command Pattern is a nice way of encapsulating all the data and logic necessary for an action.
All commands should have a handle function:
class MyCommand {
constructor(arg1, arg2) {}
handle() {}
}
You can dispatch any command syncronously or asyncronously:
var result = dispatch(MyCommand, arg1, arg2);
var callback = function (result) {}
dispatchAsync(MyCommand, arg1, arg2, callback);
class EmailNotificationCommand {
constructor(email) {
this.email = email;
},
handle() {
// Do something with this.email
console.log(this.email);
}
}
dispatchAsync(EmailNotificationCommand, '[email protected]');
Tests use Jasmine. You can run tests completely from the command line using:
VELOCITY_TEST_PACKAGES=1 meteor test-packages --driver-package velocity:html-reporter --velocity ./