react-router 3.0.4 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +6 -0
- package/README.md +3 -3
- package/docs/API.md +15 -3
- package/docs/Glossary.md +13 -12
- package/docs/README.md +3 -1
- package/docs/guides/DynamicRouting.md +1 -1
- package/docs/guides/RouteConfiguration.md +1 -1
- package/docs/guides/Testing.md +2 -1
- package/es/IndexLink.js +2 -0
- package/es/IndexRedirect.js +1 -0
- package/es/IndexRoute.js +1 -0
- package/es/Link.js +1 -0
- package/es/Redirect.js +1 -0
- package/es/Route.js +1 -0
- package/es/Router.js +8 -8
- package/es/RouterContext.js +1 -0
- package/es/TransitionUtils.js +113 -105
- package/es/createTransitionManager.js +8 -1
- package/es/withRouter.js +2 -0
- package/lib/IndexLink.js +2 -0
- package/lib/IndexRedirect.js +1 -0
- package/lib/IndexRoute.js +1 -0
- package/lib/Link.js +1 -0
- package/lib/Redirect.js +1 -0
- package/lib/Route.js +1 -0
- package/lib/Router.js +8 -8
- package/lib/RouterContext.js +1 -0
- package/lib/TransitionUtils.js +112 -105
- package/lib/createTransitionManager.js +12 -3
- package/lib/withRouter.js +2 -0
- package/package.json +5 -5
- package/umd/ReactRouter.js +819 -592
- package/umd/ReactRouter.min.js +2 -2
package/lib/TransitionUtils.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.
|
|
5
|
-
exports.runChangeHooks = runChangeHooks;
|
|
6
|
-
exports.runLeaveHooks = runLeaveHooks;
|
|
4
|
+
exports.default = getTransitionUtils;
|
|
7
5
|
|
|
8
6
|
var _AsyncUtils = require('./AsyncUtils');
|
|
9
7
|
|
|
@@ -35,121 +33,130 @@ var PendingHooks = function PendingHooks() {
|
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
var
|
|
36
|
+
function getTransitionUtils() {
|
|
37
|
+
var enterHooks = new PendingHooks();
|
|
38
|
+
var changeHooks = new PendingHooks();
|
|
40
39
|
|
|
41
|
-
function createTransitionHook(hook, route, asyncArity, pendingHooks) {
|
|
42
|
-
|
|
40
|
+
function createTransitionHook(hook, route, asyncArity, pendingHooks) {
|
|
41
|
+
var isSync = hook.length < asyncArity;
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
var transitionHook = function transitionHook() {
|
|
44
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
|
+
args[_key] = arguments[_key];
|
|
46
|
+
}
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
hook.apply(route, args);
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
if (isSync) {
|
|
51
|
+
var callback = args[args.length - 1];
|
|
52
|
+
// Assume hook executes synchronously and
|
|
53
|
+
// automatically call the callback.
|
|
54
|
+
callback();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
pendingHooks.add(transitionHook);
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
}
|
|
60
|
+
return transitionHook;
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
function getEnterHooks(routes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
63
|
+
function getEnterHooks(routes) {
|
|
64
|
+
return routes.reduce(function (hooks, route) {
|
|
65
|
+
if (route.onEnter) hooks.push(createTransitionHook(route.onEnter, route, 3, enterHooks));
|
|
66
|
+
return hooks;
|
|
67
|
+
}, []);
|
|
68
|
+
}
|
|
70
69
|
|
|
71
|
-
function getChangeHooks(routes) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
70
|
+
function getChangeHooks(routes) {
|
|
71
|
+
return routes.reduce(function (hooks, route) {
|
|
72
|
+
if (route.onChange) hooks.push(createTransitionHook(route.onChange, route, 4, changeHooks));
|
|
73
|
+
return hooks;
|
|
74
|
+
}, []);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function runTransitionHooks(length, iter, callback) {
|
|
78
|
+
if (!length) {
|
|
79
|
+
callback();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
var redirectInfo = void 0;
|
|
84
|
+
function replace(location) {
|
|
85
|
+
redirectInfo = location;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
(0, _AsyncUtils.loopAsync)(length, function (index, next, done) {
|
|
89
|
+
iter(index, replace, function (error) {
|
|
90
|
+
if (error || redirectInfo) {
|
|
91
|
+
done(error, redirectInfo); // No need to continue.
|
|
92
|
+
} else {
|
|
93
|
+
next();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}, callback);
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Runs all onEnter hooks in the given array of routes in order
|
|
101
|
+
* with onEnter(nextState, replace, callback) and calls
|
|
102
|
+
* callback(error, redirectInfo) when finished. The first hook
|
|
103
|
+
* to use replace short-circuits the loop.
|
|
104
|
+
*
|
|
105
|
+
* If a hook needs to run asynchronously, it may use the callback
|
|
106
|
+
* function. However, doing so will cause the transition to pause,
|
|
107
|
+
* which could lead to a non-responsive UI if the hook is slow.
|
|
108
|
+
*/
|
|
109
|
+
function runEnterHooks(routes, nextState, callback) {
|
|
110
|
+
enterHooks.clear();
|
|
111
|
+
var hooks = getEnterHooks(routes);
|
|
112
|
+
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
113
|
+
var wrappedNext = function wrappedNext() {
|
|
114
|
+
if (enterHooks.has(hooks[index])) {
|
|
115
|
+
next.apply(undefined, arguments);
|
|
116
|
+
enterHooks.remove(hooks[index]);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
hooks[index](nextState, replace, wrappedNext);
|
|
120
|
+
}, callback);
|
|
87
121
|
}
|
|
88
122
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Runs all onChange hooks in the given array of routes in order
|
|
125
|
+
* with onChange(prevState, nextState, replace, callback) and calls
|
|
126
|
+
* callback(error, redirectInfo) when finished. The first hook
|
|
127
|
+
* to use replace short-circuits the loop.
|
|
128
|
+
*
|
|
129
|
+
* If a hook needs to run asynchronously, it may use the callback
|
|
130
|
+
* function. However, doing so will cause the transition to pause,
|
|
131
|
+
* which could lead to a non-responsive UI if the hook is slow.
|
|
132
|
+
*/
|
|
133
|
+
function runChangeHooks(routes, state, nextState, callback) {
|
|
134
|
+
changeHooks.clear();
|
|
135
|
+
var hooks = getChangeHooks(routes);
|
|
136
|
+
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
137
|
+
var wrappedNext = function wrappedNext() {
|
|
138
|
+
if (changeHooks.has(hooks[index])) {
|
|
139
|
+
next.apply(undefined, arguments);
|
|
140
|
+
changeHooks.remove(hooks[index]);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
hooks[index](state, nextState, replace, wrappedNext);
|
|
144
|
+
}, callback);
|
|
145
|
+
}
|
|
99
146
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* which could lead to a non-responsive UI if the hook is slow.
|
|
109
|
-
*/
|
|
110
|
-
function runEnterHooks(routes, nextState, callback) {
|
|
111
|
-
enterHooks.clear();
|
|
112
|
-
var hooks = getEnterHooks(routes);
|
|
113
|
-
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
114
|
-
var wrappedNext = function wrappedNext() {
|
|
115
|
-
if (enterHooks.has(hooks[index])) {
|
|
116
|
-
next.apply(undefined, arguments);
|
|
117
|
-
enterHooks.remove(hooks[index]);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
hooks[index](nextState, replace, wrappedNext);
|
|
121
|
-
}, callback);
|
|
122
|
-
}
|
|
147
|
+
/**
|
|
148
|
+
* Runs all onLeave hooks in the given array of routes in order.
|
|
149
|
+
*/
|
|
150
|
+
function runLeaveHooks(routes, prevState) {
|
|
151
|
+
for (var i = 0, len = routes.length; i < len; ++i) {
|
|
152
|
+
if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
123
155
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
* If a hook needs to run asynchronously, it may use the callback
|
|
131
|
-
* function. However, doing so will cause the transition to pause,
|
|
132
|
-
* which could lead to a non-responsive UI if the hook is slow.
|
|
133
|
-
*/
|
|
134
|
-
function runChangeHooks(routes, state, nextState, callback) {
|
|
135
|
-
changeHooks.clear();
|
|
136
|
-
var hooks = getChangeHooks(routes);
|
|
137
|
-
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
138
|
-
var wrappedNext = function wrappedNext() {
|
|
139
|
-
if (changeHooks.has(hooks[index])) {
|
|
140
|
-
next.apply(undefined, arguments);
|
|
141
|
-
changeHooks.remove(hooks[index]);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
hooks[index](state, nextState, replace, wrappedNext);
|
|
145
|
-
}, callback);
|
|
156
|
+
return {
|
|
157
|
+
runEnterHooks: runEnterHooks,
|
|
158
|
+
runChangeHooks: runChangeHooks,
|
|
159
|
+
runLeaveHooks: runLeaveHooks
|
|
160
|
+
};
|
|
146
161
|
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Runs all onLeave hooks in the given array of routes in order.
|
|
150
|
-
*/
|
|
151
|
-
function runLeaveHooks(routes, prevState) {
|
|
152
|
-
for (var i = 0, len = routes.length; i < len; ++i) {
|
|
153
|
-
if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
162
|
+
module.exports = exports['default'];
|
|
@@ -16,6 +16,8 @@ var _computeChangedRoutes3 = _interopRequireDefault(_computeChangedRoutes2);
|
|
|
16
16
|
|
|
17
17
|
var _TransitionUtils = require('./TransitionUtils');
|
|
18
18
|
|
|
19
|
+
var _TransitionUtils2 = _interopRequireDefault(_TransitionUtils);
|
|
20
|
+
|
|
19
21
|
var _isActive2 = require('./isActive');
|
|
20
22
|
|
|
21
23
|
var _isActive3 = _interopRequireDefault(_isActive2);
|
|
@@ -39,8 +41,15 @@ function hasAnyProperties(object) {
|
|
|
39
41
|
function createTransitionManager(history, routes) {
|
|
40
42
|
var state = {};
|
|
41
43
|
|
|
44
|
+
var _getTransitionUtils = (0, _TransitionUtils2.default)(),
|
|
45
|
+
runEnterHooks = _getTransitionUtils.runEnterHooks,
|
|
46
|
+
runChangeHooks = _getTransitionUtils.runChangeHooks,
|
|
47
|
+
runLeaveHooks = _getTransitionUtils.runLeaveHooks;
|
|
48
|
+
|
|
42
49
|
// Signature should be (location, indexOnly), but needs to support (path,
|
|
43
50
|
// query, indexOnly)
|
|
51
|
+
|
|
52
|
+
|
|
44
53
|
function isActive(location, indexOnly) {
|
|
45
54
|
location = history.createLocation(location);
|
|
46
55
|
|
|
@@ -72,7 +81,7 @@ function createTransitionManager(history, routes) {
|
|
|
72
81
|
changeRoutes = _computeChangedRoutes.changeRoutes,
|
|
73
82
|
enterRoutes = _computeChangedRoutes.enterRoutes;
|
|
74
83
|
|
|
75
|
-
|
|
84
|
+
runLeaveHooks(leaveRoutes, state);
|
|
76
85
|
|
|
77
86
|
// Tear down confirmation hooks for left routes
|
|
78
87
|
leaveRoutes.filter(function (route) {
|
|
@@ -80,10 +89,10 @@ function createTransitionManager(history, routes) {
|
|
|
80
89
|
}).forEach(removeListenBeforeHooksForRoute);
|
|
81
90
|
|
|
82
91
|
// change and enter hooks are run in series
|
|
83
|
-
|
|
92
|
+
runChangeHooks(changeRoutes, state, nextState, function (error, redirectInfo) {
|
|
84
93
|
if (error || redirectInfo) return handleErrorOrRedirect(error, redirectInfo);
|
|
85
94
|
|
|
86
|
-
|
|
95
|
+
runEnterHooks(enterRoutes, nextState, finishEnterHooks);
|
|
87
96
|
});
|
|
88
97
|
|
|
89
98
|
function finishEnterHooks(error, redirectInfo) {
|
package/lib/withRouter.js
CHANGED
|
@@ -36,6 +36,8 @@ function withRouter(WrappedComponent, options) {
|
|
|
36
36
|
var withRef = options && options.withRef;
|
|
37
37
|
|
|
38
38
|
var WithRouter = (0, _createReactClass2.default)({
|
|
39
|
+
displayName: 'WithRouter',
|
|
40
|
+
|
|
39
41
|
mixins: [(0, _ContextUtils.ContextSubscriber)('router')],
|
|
40
42
|
|
|
41
43
|
contextTypes: { router: _PropTypes.routerShape },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "A complete routing library for React",
|
|
5
5
|
"files": [
|
|
6
6
|
"*.md",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"warning": "^3.0.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"react": "^0.14.0 || ^15.0.0"
|
|
45
|
+
"react": "^0.14.0 || ^15.0.0 || ^16.0.0-rc"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"babel-cli": "^6.11.4",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"mocha": "^3.2.0",
|
|
80
80
|
"pretty-bytes": "^4.0.2",
|
|
81
81
|
"qs": "^6.2.1",
|
|
82
|
-
"react": "^
|
|
83
|
-
"react-
|
|
84
|
-
"react-
|
|
82
|
+
"react": "^16.0.0-rc",
|
|
83
|
+
"react-addons-css-transition-group": "^15.6.0",
|
|
84
|
+
"react-dom": "^16.0.0-rc",
|
|
85
85
|
"rimraf": "^2.5.4",
|
|
86
86
|
"style-loader": "^0.16.1",
|
|
87
87
|
"webpack": "^1.13.1",
|