connect-traversal
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/** | ||
@@ -6,10 +8,12 @@ * Chain object, helps to build handlers | ||
function Chain() { | ||
this._method = '*'; | ||
this._name = '*'; | ||
this._parent = '*'; | ||
this._allCounter = 0; | ||
this._all = {}; | ||
this._only = {}; | ||
this._method = this.ignore; | ||
this._name = this.ignore; | ||
this._parent = this.ignore; | ||
this._order = 0; | ||
} | ||
Chain.prototype.ignore = '*'; | ||
Chain.prototype.allAttr = 'all'; | ||
Chain.prototype.onlyAttr = 'only'; | ||
/** | ||
@@ -53,2 +57,6 @@ * Method setter | ||
Chain.prototype.getCallbacks = function(name, parent, method) { | ||
name = name || this.ignore; | ||
parent = parent || this.ignore; | ||
method = method || this.ignore; | ||
var callbacks = {}, | ||
@@ -58,36 +66,32 @@ result = [], | ||
var only = self.__getCallbacks.apply(self, ['only', name, parent, method, '*']); | ||
var only = self.__getCallbacks(this.onlyAttr, name, parent, method, this.ignore); | ||
if (!only) return []; | ||
callbacks[only.index] = only.callbacks; | ||
callbacks[only.order] = only.callbacks; | ||
name = name || '*'; | ||
parent = parent || '*'; | ||
method = method || '*'; | ||
// get cases for all callbacks. | ||
var cases = [ | ||
['all', '*', '*', '*'] | ||
[this.allAttr, this.ignore, this.ignore, this.ignore] | ||
]; | ||
if (method !== '*') { | ||
cases.push(['all', '*', '*', method]); | ||
if (parent !== '*') { | ||
cases.push(['all', '*', parent, method]); | ||
if (name !== '*') { | ||
cases.push(['all', name, parent, method]); | ||
if (method !== this.ignore) { | ||
cases.push([this.allAttr, this.ignore, this.ignore, method]); | ||
if (parent !== this.ignore) { | ||
cases.push([this.allAttr, this.ignore, parent, method]); | ||
if (name !== this.ignore) { | ||
cases.push([this.allAttr, name, parent, method]); | ||
} | ||
} else { | ||
if (name !== '*') { | ||
cases.push(['all', name, '*', method]); | ||
if (name !== this.ignore) { | ||
cases.push([this.allAttr, name, this.ignore, method]); | ||
} | ||
} | ||
} | ||
if (parent !== '*') { | ||
cases.push(['all', '*', parent, '*']); | ||
if (name !== '*') { | ||
cases.push(['all', name, parent, '*']); | ||
if (parent !== this.ignore) { | ||
cases.push([this.allAttr, this.ignore, parent, this.ignore]); | ||
if (name !== this.ignore) { | ||
cases.push([this.allAttr, name, parent, this.ignore]); | ||
} | ||
} | ||
if (name !== '*') { | ||
cases.push(['all', name, '*', '*']); | ||
if (name !== this.ignore) { | ||
cases.push([this.allAttr, name, this.ignore, this.ignore]); | ||
} | ||
@@ -97,3 +101,3 @@ cases.forEach(function(params) { | ||
if (fns) { | ||
callbacks[fns.index] = fns.callbacks; | ||
callbacks[fns.order] = fns.callbacks; | ||
} | ||
@@ -113,3 +117,3 @@ }); | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
args.unshift('all'); | ||
args.unshift(this.allAttr); | ||
return this.__reg.apply(this, args); | ||
@@ -124,3 +128,3 @@ }; | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
args.unshift('only'); | ||
args.unshift(this.onlyAttr); | ||
return this.__reg.apply(this, args); | ||
@@ -132,16 +136,18 @@ }; | ||
if (!callbacks.length) { | ||
throw Error('registerPath() requires callback functions'); | ||
throw TypeError('required at least 1 callback'); | ||
} | ||
callbacks.forEach(function(fn) { | ||
if ('function' == typeof fn) return; | ||
throw new Error("registerPath() requires callback functions of 'function' type"); | ||
throw new TypeError("required callback functions of 'function' type"); | ||
}); | ||
if (!this['_' + type][this._name]) this['_' + type][this._name] = {}; | ||
if (!this['_' + type][this._name][this._parent]) this['_' + type][this._name][this._parent] = {}; | ||
this['_' + type][this._name][this._parent][this._method] = { | ||
index: this._allCounter++, | ||
if (!this['_' + type]) this['_' + type] = {}; | ||
var typeObj = this['_' + type]; | ||
if (!typeObj[this._name]) typeObj[this._name] = {}; | ||
if (!typeObj[this._name][this._parent]) typeObj[this._name][this._parent] = {}; | ||
typeObj[this._name][this._parent][this._method] = { | ||
order: this._order++, | ||
callbacks: callbacks | ||
}; | ||
return this; | ||
} | ||
}; | ||
@@ -148,0 +154,0 @@ Chain.prototype.__getCallbacks = function(type, name, parent, method, def) { |
{ | ||
"name": "connect-traversal", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Middleware for Connect and Express application which allows to use URL traversal instead of URL dispatching.", | ||
@@ -40,4 +40,4 @@ "keywords": [ | ||
"readmeFilename": "README.md", | ||
"_id": "connect-traversal@0.3.0", | ||
"_id": "connect-traversal@0.3.1", | ||
"_from": "connect-traversal@latest" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62987
360