find-my-way
Advanced tools
Comparing version 5.5.0 to 5.5.1
@@ -8,4 +8,2 @@ 'use strict' | ||
constructor () { | ||
this.constrainer = HandlerStorage.prototype.constrainer | ||
this.handlers = [] // unoptimized list of handler objects for which the fast matcher function will be compiled | ||
@@ -23,3 +21,3 @@ this.hasConstraints = false | ||
// This is the hot path for node handler finding -- change with care! | ||
getMatchingHandler (derivedConstraints) { | ||
getMatchingHandler (constrainer, derivedConstraints) { | ||
if (derivedConstraints === undefined) { | ||
@@ -31,3 +29,3 @@ return this.unconstrainedHandler | ||
// This node is constrained, use the performant precompiled constraint matcher | ||
return this._getHandlerMatchingConstraints(derivedConstraints) | ||
return this._getHandlerMatchingConstraints(constrainer, derivedConstraints) | ||
} | ||
@@ -69,5 +67,5 @@ | ||
// Slot for the compiled constraint matching function | ||
_getHandlerMatchingConstraints (derivedConstraints) { | ||
_getHandlerMatchingConstraints (constrainer, derivedConstraints) { | ||
if (this.compiledHandler === null) { | ||
this.compiledHandler = this._compileGetHandlerMatchingConstraints() | ||
this.compiledHandler = this._compileGetHandlerMatchingConstraints(constrainer) | ||
} | ||
@@ -80,4 +78,4 @@ return this.compiledHandler(derivedConstraints) | ||
// The store's implementation comes from the strategies provided to the Router. | ||
_buildConstraintStore (constraint) { | ||
const store = this.constrainer.newStoreForConstraint(constraint) | ||
_buildConstraintStore (constrainer, constraint) { | ||
const store = constrainer.newStoreForConstraint(constraint) | ||
@@ -118,3 +116,3 @@ for (let i = 0; i < this.handlers.length; i++) { | ||
// We consider all this compiling function complexity to be worth it, because the naive implementation that just loops over the handlers asking which stores match is quite a bit slower. | ||
_compileGetHandlerMatchingConstraints () { | ||
_compileGetHandlerMatchingConstraints (constrainer) { | ||
this.constrainedHandlerStores = {} | ||
@@ -134,3 +132,3 @@ let constraints = new Set() | ||
for (const constraint of constraints) { | ||
this.constrainedHandlerStores[constraint] = this._buildConstraintStore(constraint) | ||
this.constrainedHandlerStores[constraint] = this._buildConstraintStore(constrainer, constraint) | ||
} | ||
@@ -137,0 +135,0 @@ |
@@ -35,3 +35,2 @@ 'use strict' | ||
const sanitizeUrl = require('./lib/url-sanitizer') | ||
const HandlerStorage = require('./handler_storage') | ||
@@ -90,3 +89,2 @@ const httpMethods = http.METHODS | ||
this.constrainer = new Constrainer(opts.constraints) | ||
HandlerStorage.prototype.constrainer = this.constrainer | ||
} | ||
@@ -357,3 +355,3 @@ | ||
if (pathIndex === pathLen) { | ||
const handle = currentNode.handlerStorage.getMatchingHandler(derivedConstraints) | ||
const handle = currentNode.handlerStorage.getMatchingHandler(this.constrainer, derivedConstraints) | ||
@@ -360,0 +358,0 @@ if (handle !== null && handle !== undefined) { |
{ | ||
"name": "find-my-way", | ||
"version": "5.5.0", | ||
"version": "5.5.1", | ||
"description": "Crazy fast http radix based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
267888
70
6883