|
1 | 1 | /* jshint -W084 */ |
2 | | - |
3 | 2 | var PathUtils = require('./PathUtils'); |
4 | 3 |
|
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 | | - |
16 | 4 | function deepSearch(route, pathname, query) { |
17 | 5 | // Check the subtree first to find the most deeply-nested match. |
18 | 6 | var childRoutes = route.childRoutes; |
@@ -50,20 +38,31 @@ function deepSearch(route, pathname, query) { |
50 | 38 | return null; |
51 | 39 | } |
52 | 40 |
|
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); |
62 | 55 |
|
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 | + } |
65 | 65 |
|
66 | | - return match; |
67 | | -}; |
| 66 | +} |
68 | 67 |
|
69 | 68 | module.exports = Match; |
0 commit comments