Permalink
Browse files

[fix] readme

  • Loading branch information...
1 parent 707862e commit 505eee63bd61da6d31c6a7b227e51fcfd3447c4f @bmeck committed Jan 11, 2013
Showing with 17 additions and 16 deletions.
  1. +11 −10 lib/index.js
  2. +1 −0 package.json
  3. +5 −6 readme.md
View
@@ -15,6 +15,8 @@ exports.Understudy = function() {
return this;
}
+function noop() {}
+
function registrar(property) {
return function (action, callback) {
if (typeof action === 'string') {
@@ -45,40 +47,39 @@ function perform(action /* , args..., callback */) {
//
function iterate(self, interceptors, args, after) {
if (!interceptors) {
- after && after.apply(self, args);
+ after.apply(self, args);
return;
}
interceptors = interceptors.concat();
var i = 0;
var l = interceptors.length;
- function next() {
+ function nextInterceptor() {
if (arguments[0]) {
i = l;
}
if (i === l) {
i++;
- after && after.apply(self, arguments);
+ after.apply(self, arguments);
}
else if (i < l) {
var used = false;
var interceptor = interceptors[i++];
- interceptor.apply(self, Array.prototype.slice.call(arguments, 1).concat(function () {
+ interceptor.apply(self, Array.prototype.slice.call(arguments, 1).concat(function next() {
//
// Do not allow multiple continuations
//
if (used) return;
used = true;
- next.apply(null, arguments);
+ nextInterceptor.apply(null, arguments);
}));
}
}
- next.apply(self, args);
+ nextInterceptor.apply(self, args);
}
function finish() {
- callback && callback.apply(this, arguments);
- iterate(this, this._after_interceptors && this._after_interceptors[action], Array.prototype.slice.call(arguments), null);
+ callback.apply(this, arguments);
+ iterate(this, this._after_interceptors && this._after_interceptors[action], arguments, noop);
}
- iterate(this, this._before_interceptors && this._before_interceptors[action], args, finish);
+ iterate(this, this._before_interceptors && this._before_interceptors[action], args, finish || noop);
return this;
}
-
View
@@ -5,6 +5,7 @@
"tags": ["buzzwords"],
"version": "1.1.0",
"main": "lib/index.js",
+ "repository": {"type":"git", "url":"git@github.com:bmeck/node-understudy"},
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
View
@@ -33,12 +33,11 @@ function afterHandler(config, next) {
}
actor.before('load:plugins', beforeHandler);
actor.after('load:plugins', afterHandler);
-actor.perform('load:plugins', config, function (err, config, allowAfter) {
+actor.perform('load:plugins', config, function (err, config) {
// start up app
// ...
- // opt-in for `after` interceptors
+ // when this function returns if there is not an err, invoke the `after` functions with the arguments
actor.before.remove('load:plugins', beforeHandler);
- allowAfter();
});
```
@@ -68,9 +67,9 @@ actor.perform('load:plugins', config, function (err, config, allowAfter) {
2. At the end of the arguments to the event will be added a `next` function.
2. 1. The `next` function is used for passing state via arguments and accepts an error first argument in order to fail fast.
3. Each before interceptors will be fired in order after the previous fires the `next` function.
-4. After all interceptors have been fired the `done` function will fire with the arguments passed to the next function and an opt-in function to allow after interceptors.
-5. If the `done` function opts-in to after interceptors the after interceptors will be fired in order after the previous fires the `next` function.
+4. After all interceptors have been fired the `done` function will fire with the arguments passed to the next function.
+5. If the `done` function did not have an error argument the after interceptors will be fired in order after the previous fires the `next` function.
## Examples
-See the example directory
+See the example directory

0 comments on commit 505eee6

Please sign in to comment.