Skip to content

Commit

Permalink
Use ES6 notation for Match static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Feb 24, 2015
1 parent 7c1d079 commit 0f517cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
49 changes: 24 additions & 25 deletions modules/Match.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/* jshint -W084 */

var PathUtils = require('./PathUtils');

class Match {

constructor(pathname, params, query, routes) {
this.pathname = pathname;
this.params = params;
this.query = query;
this.routes = routes;
}

}

function deepSearch(route, pathname, query) {
// Check the subtree first to find the most deeply-nested match.
var childRoutes = route.childRoutes;
Expand Down Expand Up @@ -50,20 +38,31 @@ function deepSearch(route, pathname, query) {
return null;
}

/**
* Attempts to match depth-first a route in the given route's
* subtree against the given path and returns the match if it
* succeeds, null if no match can be made.
*/
Match.findMatchForPath = function (routes, path) {
var pathname = PathUtils.withoutQuery(path);
var query = PathUtils.extractQuery(path);
var match = null;
class Match {

/**
* Attempts to match depth-first a route in the given route's
* subtree against the given path and returns the match if it
* succeeds, null if no match can be made.
*/
static findMatch(routes, path) {
var pathname = PathUtils.withoutQuery(path);
var query = PathUtils.extractQuery(path);
var match = null;

for (var i = 0, len = routes.length; match == null && i < len; ++i)
match = deepSearch(routes[i], pathname, query);

for (var i = 0, len = routes.length; match == null && i < len; ++i)
match = deepSearch(routes[i], pathname, query);
return match;
}

constructor(pathname, params, query, routes) {
this.pathname = pathname;
this.params = params;
this.query = query;
this.routes = routes;
}

return match;
};
}

module.exports = Match;
2 changes: 1 addition & 1 deletion modules/createRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function createRouter(options) {
* match can be made.
*/
match: function (path) {
return Match.findMatchForPath(this.routes, path);
return Match.findMatch(this.routes, path);
},

/**
Expand Down

0 comments on commit 0f517cf

Please sign in to comment.