AnchorJS
AnchorJS is a (express inspired) middleware layer for scaffolding asynchronous JavaScript methods.
Installation
Node.js
$ npm install anchorjs
Browser
Include the Anchor.js browser build in your pages.
<script src="anchor.js" type="text/javascript"></script>
This will provide anchor
as a global object, or define
it if you are using AMD.
##Example
Middleware
var anchor = require('anchorjs');
function Clock(){
this._tick = 'tick';
this._tock = 'tock';
}
anchor(Clock.prototype)
.use(function(ctx, next){
ctx.logs = ['clock',this._tick];
next();
})
.use('tock',function(ctx, next){
ctx.logs.push(this._tock);
next();
})
.define(['tick','tock'],function(ctx, done){
ctx.logs.push('done');
done(null, ctx.logs);
});
var clock1 = new Clock();
var clock2 = new Clock();
clock2.use('tick',function(ctx, next){
ctx.logs.push('tick2');
next();
});
clock2.use('tock',function(ctx, next){
next('booooom');
});
clock1.tick(console.log.bind(console));
clock1.tock(console.log.bind(console));
clock2.tick(console.log.bind(console));
clock2.tock(console.log.bind(console));
Changelog
0.2.4
- ADD array support for middleware arguments
0.2.3
0.2.2
0.2.1
- Clean up unnecessary API methods
0.2.0
- ADD params parser middleware
0.1.2
License
MIT