Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

CapsuleCat/CommandsMeteorPackage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Commands for Meteor

Build Status MIT License

Dispatch reusable commands synchronously or asynchronously.

Installation

meteor add capsulecat:commands

The Command Pattern

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.

Documentation

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);

Example Code

class EmailNotificationCommand {
  constructor(email) {
    this.email = email;
  },
  handle() {
    // Do something with this.email
    console.log(this.email);
  }
}

dispatchAsync(EmailNotificationCommand, '[email protected]');

Running Tests

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 ./

About

Commands package written for Meteor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published