🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

chaining-tool

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chaining-tool - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+1
-1
bower.json
{
"name": "chaining-tool",
"main": "index.js",
"version": "0.0.2",
"version": "0.0.3",
"homepage": "https://github.com/maxazan/chaining-tool",

@@ -6,0 +6,0 @@ "authors": [

@@ -14,7 +14,13 @@ /**

/**
* Add handler to the end of chain
* Add handler or handlers to the end of chain
* @param {function} handler
*/
Chain.prototype.add = function(handler) {
this.handlers.push(handler);
if(typeof(handler)=="function"){
this.handlers.push(handler);
}else{
for (var i = 0; i < handler.length; i++) {
this.handlers.push(handler[i]);
}
}
};

@@ -21,0 +27,0 @@

{
"name": "chaining-tool",
"version": "0.0.2",
"version": "0.0.3",
"description": "Chain of responsibility",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -89,2 +89,64 @@ var assert = require("assert");

});
it('add method test', function(done) {
var handlers = [];
handlers[0] = function(context, next) {
context.request.test = 1;
next();
};
handlers[1] = function(context, next) {
next();
};
another_handler = function(context, next) {
context.request.test = 2;
next();
};
var context = {
request: {},
response: {}
};
var oncomplete = function(context) {
assert.equal(context.request.test, 2);
done();
};
var oninterrupt = function(context) {
assert.ok(false);
};
var chain = new Chain(handlers);
chain.add(another_handler);
chain.start(context, oncomplete, oninterrupt);
});
it('add array method test', function(done) {
var handlers = [];
handlers[0] = function(context, next) {
context.request.test = 1;
next();
};
var another_handler = [];
another_handler[0] = function(context, next) {
next();
};
another_handler[1] = function(context, next) {
context.request.test = 2;
next();
};
var context = {
request: {},
response: {}
};
var oncomplete = function(context) {
assert.equal(context.request.test, 2);
done();
};
var oninterrupt = function(context) {
assert.ok(false);
};
var chain = new Chain(handlers);
chain.add(another_handler);
chain.start(context, oncomplete, oninterrupt);
});
it('memory usage test', function(done) {

@@ -91,0 +153,0 @@ var handlers = [];