Skip to content

Commit 7166fd5

Browse files
committed
Use ES6 class syntax
1 parent 0a9cbf0 commit 7166fd5

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

modules/Match.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
var Path = require('./utils/Path');
44

5-
function Match(pathname, params, query, routes) {
6-
this.pathname = pathname;
7-
this.params = params;
8-
this.query = query;
9-
this.routes = routes;
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+
1014
}
1115

1216
function deepSearch(route, pathname, query) {

modules/Route.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,47 @@ var invariant = require('react/lib/invariant');
33
var warning = require('react/lib/warning');
44
var Path = require('./utils/Path');
55

6-
function Route(name, path, ignoreScrollBehavior, isDefault, isNotFound, onEnter, onLeave, handler) {
7-
this.name = name;
8-
this.path = path;
9-
this.paramNames = Path.extractParamNames(this.path);
10-
this.ignoreScrollBehavior = !!ignoreScrollBehavior;
11-
this.isDefault = !!isDefault;
12-
this.isNotFound = !!isNotFound;
13-
this.onEnter = onEnter;
14-
this.onLeave = onLeave;
15-
this.handler = handler;
16-
}
6+
class Route {
7+
8+
constructor(name, path, ignoreScrollBehavior, isDefault, isNotFound, onEnter, onLeave, handler) {
9+
this.name = name;
10+
this.path = path;
11+
this.paramNames = Path.extractParamNames(this.path);
12+
this.ignoreScrollBehavior = !!ignoreScrollBehavior;
13+
this.isDefault = !!isDefault;
14+
this.isNotFound = !!isNotFound;
15+
this.onEnter = onEnter;
16+
this.onLeave = onLeave;
17+
this.handler = handler;
18+
}
1719

18-
/**
19-
* Appends the given route to this route's child routes.
20-
*/
21-
Route.prototype.appendChild = function (route) {
22-
invariant(
23-
route instanceof Route,
24-
'route.appendChild must use a valid Route'
25-
);
20+
/**
21+
* Appends the given route to this route's child routes.
22+
*/
23+
appendChild(route) {
24+
invariant(
25+
route instanceof Route,
26+
'route.appendChild must use a valid Route'
27+
);
2628

27-
if (!this.childRoutes)
28-
this.childRoutes = [];
29+
if (!this.childRoutes)
30+
this.childRoutes = [];
2931

30-
this.childRoutes.push(route);
31-
};
32+
this.childRoutes.push(route);
33+
}
3234

33-
Route.prototype.toString = function () {
34-
var string = '<Route';
35+
toString() {
36+
var string = '<Route';
3537

36-
if (this.name)
37-
string += ` name="${this.name}"`;
38+
if (this.name)
39+
string += ` name="${this.name}"`;
3840

39-
string += ` path="${this.path}">`;
41+
string += ` path="${this.path}">`;
4042

41-
return string;
42-
};
43+
return string;
44+
}
45+
46+
}
4347

4448
var _currentRoute;
4549

0 commit comments

Comments
 (0)