Skip to content

Commit 0f517cf

Browse files
committed
Use ES6 notation for Match static methods
1 parent 7c1d079 commit 0f517cf

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

modules/Match.js

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
/* jshint -W084 */
2-
32
var PathUtils = require('./PathUtils');
43

5-
class Match {
6-
7-
constructor(pathname, params, query, routes) {
8-
this.pathname = pathname;
9-
this.params = params;
10-
this.query = query;
11-
this.routes = routes;
12-
}
13-
14-
}
15-
164
function deepSearch(route, pathname, query) {
175
// Check the subtree first to find the most deeply-nested match.
186
var childRoutes = route.childRoutes;
@@ -50,20 +38,31 @@ function deepSearch(route, pathname, query) {
5038
return null;
5139
}
5240

53-
/**
54-
* Attempts to match depth-first a route in the given route's
55-
* subtree against the given path and returns the match if it
56-
* succeeds, null if no match can be made.
57-
*/
58-
Match.findMatchForPath = function (routes, path) {
59-
var pathname = PathUtils.withoutQuery(path);
60-
var query = PathUtils.extractQuery(path);
61-
var match = null;
41+
class Match {
42+
43+
/**
44+
* Attempts to match depth-first a route in the given route's
45+
* subtree against the given path and returns the match if it
46+
* succeeds, null if no match can be made.
47+
*/
48+
static findMatch(routes, path) {
49+
var pathname = PathUtils.withoutQuery(path);
50+
var query = PathUtils.extractQuery(path);
51+
var match = null;
52+
53+
for (var i = 0, len = routes.length; match == null && i < len; ++i)
54+
match = deepSearch(routes[i], pathname, query);
6255

63-
for (var i = 0, len = routes.length; match == null && i < len; ++i)
64-
match = deepSearch(routes[i], pathname, query);
56+
return match;
57+
}
58+
59+
constructor(pathname, params, query, routes) {
60+
this.pathname = pathname;
61+
this.params = params;
62+
this.query = query;
63+
this.routes = routes;
64+
}
6565

66-
return match;
67-
};
66+
}
6867

6968
module.exports = Match;

modules/createRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function createRouter(options) {
185185
* match can be made.
186186
*/
187187
match: function (path) {
188-
return Match.findMatchForPath(this.routes, path);
188+
return Match.findMatch(this.routes, path);
189189
},
190190

191191
/**

0 commit comments

Comments
 (0)