catberry-module v1.0.1
#Module basic implementation for catberry
##Description Catberry has module interface that requires from developer to implement "render", "handle" and "submit" methods in Catberry modules.
First argument of each of these methods is a name of placeholder, event or form. Developer must switch on this name and route invocations to another methods that implement logic exactly for this placeholder, event or form.
For example, with this module you can just write:
var util = require('util'),
ModuleBase = require('catberry-module');
util.inherits(Module, ModuleBase);
function Module() {
}
Module.prototype.renderSome = function (callback) {
// render logic for placeholder "some"
};
Module.prototype.renderSomeOtherExample = function (callback) {
// render logic for placeholder "some-other_example"
};
Module.prototype.renderAnother = function (callback) {
// render logic for placeholder "another"
};
Module.prototype.handleSome = function (isStarted, args, callback) {
// handle logic for event "some"
};
Module.prototype.handleAnother = function (isStarted, args, callback) {
// handle logic for event "another"
};
Module.prototype.submitSome = function (formObject, callback) {
// submit logic for form "some"
};
Module.prototype.submitAnother = function (formObject, callback) {
// submit logic for form "another"
};
instead
function Module() {
}
Module.prototype.render = function (placeholderName, callback) {
switch (placeholderName) {
case 'some':
renderSome(callback);
break;
case 'some-other_example':
renderSomeOtherExample(callback);
break;
case 'another':
renderAnother(callback);
break;
default:
callback(null, {});
}
};
Module.prototype.handle = function (eventName, isStarted, args, callback) {
switch (eventName) {
case 'some':
handleSome(isStarted, args, callback);
break;
case 'another':
handleAnother(isStarted, args, callback);
break;
default:
callback();
}
};
Module.prototype.submit = function (formName, formObject, callback) {
switch (formName) {
case 'some':
renderSome(formObject, callback);
break;
case 'another':
renderAnother(formObject, callback);
break;
default:
callback();
}
};
Module.prototype.renderSome = function (callback) {
// render logic for placeholder "some"
};
Module.prototype.renderSomeOtherExample = function (callback) {
// render logic for placeholder "some-other_example"
};
Module.prototype.renderAnother = function (callback) {
// render logic for placeholder "another"
};
Module.prototype.handleSome = function (isStarted, args, callback) {
// handle logic for event "some"
};
Module.prototype.handleAnother = function (isStarted, args, callback) {
// handle logic for event "another"
};
Module.prototype.submitSome = function (formObject, callback) {
// submit logic for form "some"
};
Module.prototype.submitAnother = function (formObject, callback) {
// submit logic for form "another"
};
##Contribution
If you have found a bug, please create pull request with mocha
unit-test which reproduces it or describe all details in issue if you can not
implement test. If you want to propose some improvements just create issue or
pull request but please do not forget to use npm test
to be sure that your
code is awesome.
All changes should satisfy this Code Style Guide.
Also your changes should be covered by unit tests using mocha.
Denis Rechkunov denis.rechkunov@gmail.com