Permalink
Browse files

More code style improvements -- group similar code next to each other.

  • Loading branch information...
1 parent 3a77ab0 commit 42f4765c4b89c8229a070a5afda0c016fedc8621 @bnoguchi committed Feb 29, 2012
Showing with 31 additions and 35 deletions.
  1. +25 −23 lib/modules/everymodule.js
  2. +6 −12 lib/stepSequence.js
View
@@ -10,23 +10,9 @@ var routeDescPrefix = {
, post: 'ROUTE (POST)'
};
-// Returns a function used for declaring new route triggered sequences
-// associated with the uri route and the http `method`
-// @param {String} method is the http method (e.g, 'get', 'post')
-function route (method) {
- return function (alias, description) { /* `this` is `everyModule` */
- if (description)
- description = routeDescPrefix[method.toLowerCase()] + ' - ' + description;
- this.configurable(alias, description);
- var name = method + ':' + alias;
- this._currSeq =
- this._stepSequences[name] || (this._stepSequences[name] = new RouteTriggeredSequence(name, this));
- return this;
- };
-}
-
var everyModule = module.exports = {
name: 'everymodule'
+
, definit: function definit (fn) {
// Remove any prior `init` that was assigned directly to the object via
// definit and not assigned via prototypal inheritance
@@ -44,14 +30,18 @@ var everyModule = module.exports = {
};
return this;
}
- , get: route('get')
- , post: route('post')
+
+ , _stepSequences: {}
, stepseq: function stepseq (name, description) {
this.configurable(name, description);
- this._currSeq =
+ this._currSeq =
this._stepSequences[name] || (this._stepSequences[name] = new StepSequence(name, this));
return this;
}
+
+ // _configurable maps parameter names to descriptions
+ // It is used for introspection with this.configurable()
+ , _configurable: {}
, configurable: function configurable (arg, description, wrapper) {
if (!arguments.length)
// Calling module.configurable() returns a listing of the module's
@@ -270,13 +260,25 @@ var everyModule = module.exports = {
// _steps maps step names to step objects
// A step object is { accepts: [...], promises: [...] }
, _steps: {}
+};
- , _stepSequences: {}
+everyModule.get = route('get');
+everyModule.post = route('post');
- // _configurable maps parameter names to descriptions
- // It is used for introspection with this.configurable()
- , _configurable: {}
-};
+// Returns a function used for declaring new route triggered sequences
+// associated with the uri route and the http `method`
+// @param {String} method is the http method (e.g, 'get', 'post')
+function route (method) {
+ return function (alias, description) { /* `this` is `everyModule` */
+ if (description)
+ description = routeDescPrefix[method.toLowerCase()] + ' - ' + description;
+ this.configurable(alias, description);
+ var name = method + ':' + alias;
+ this._currSeq =
+ this._stepSequences[name] || (this._stepSequences[name] = new RouteTriggeredSequence(name, this));
+ return this;
+ };
+}
Object.defineProperty(everyModule, 'shouldSetup', { get: function () {
return ! Object.keys(this.submodules).length;
View
@@ -123,20 +123,18 @@ StepSequence.prototype = {
Object.defineProperty(StepSequence.prototype, 'steps', {
get: function () {
- // Compile the steps by pulling the step names
- // from the module
+ // Compile the steps by pulling the step names from the module
var allSteps = this.module._steps
, orderedSteps = this.orderedStepNames.map( function (stepName) {
return allSteps[stepName];
})
, seq = this;
function compileSteps () {
- var ret
- , paramsToDate = []
+ var paramsToDate = []
, missingParams;
- ret = orderedSteps.map( function (step, i) {
+ var steps = orderedSteps.map( function (step, i) {
var meta = { missing: [], step: step, missingParams: [], paramsToDate: {} };
if (! ('promises' in step)) {
meta.missing.push('promises');
@@ -164,10 +162,9 @@ Object.defineProperty(StepSequence.prototype, 'steps', {
meta.missing.push('its function');
return meta;
-
});
- return ret;
+ return steps;
}
var compiledSteps;
@@ -177,8 +174,7 @@ Object.defineProperty(StepSequence.prototype, 'steps', {
return compiledSteps.filter( function (stepMeta) {
return stepMeta.missing.length > 0;
}).map( function (stepMeta) {
- var error = 'is missing: ' +
- stepMeta.missing.join(', ');
+ var error = 'is missing: ' + stepMeta.missing.join(', ');
return { name: stepMeta.step.name, error: error };
});
} });
@@ -202,7 +198,5 @@ Object.defineProperty(StepSequence.prototype, 'steps', {
});
Object.defineProperty(StepSequence.prototype, 'debug', {
- get: function () {
- return this.module.everyauth.debug;
- }
+ get: function () { return this.module.everyauth.debug; }
});

0 comments on commit 42f4765

Please sign in to comment.