react-router 3.0.4 → 3.0.5

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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## [v3.0.5](https://github.com/ReactTraining/react-router/compare/v3.0.4...v3.0.5)
2
+ > Apr 10, 2017
3
+
4
+ - Manually set displayName for components
5
+ - Async hooks could be removed during simultaneous server requests (#4941 by @s-yadav)
6
+
1
7
  ## [v3.0.4](https://github.com/ReactTraining/react-router/compare/v3.0.3...v3.0.4)
2
8
  > Apr 9, 2017
3
9
 
package/README.md CHANGED
@@ -9,11 +9,11 @@ React Router keeps your UI in sync with the URL. It has a simple API with powerf
9
9
  [![Codecov][codecov-badge]][codecov]
10
10
  [![Discord][discord-badge]][discord]
11
11
 
12
- ### v4 Is Coming
12
+ ### 4.0 is here!
13
13
 
14
- The next version of React Router (v4) is in beta now.
14
+ The next version of React Router (4.0) has been released! Check out the `master` branch.
15
15
 
16
- [v4 Documentation](https://reacttraining.com/react-router/)
16
+ [4.0 Documentation](https://reacttraining.com/react-router/)
17
17
 
18
18
  ### Docs & Help
19
19
 
package/es/IndexLink.js CHANGED
@@ -8,6 +8,8 @@ import Link from './Link';
8
8
  * An <IndexLink> is used to link to an <IndexRoute>.
9
9
  */
10
10
  var IndexLink = createReactClass({
11
+ displayName: 'IndexLink',
12
+
11
13
  render: function render() {
12
14
  return React.createElement(Link, _extends({}, this.props, { onlyActiveOnIndex: true }));
13
15
  }
@@ -10,6 +10,7 @@ import { falsy } from './InternalPropTypes';
10
10
  */
11
11
  /* eslint-disable react/require-render-return */
12
12
  var IndexRedirect = createReactClass({
13
+ displayName: 'IndexRedirect',
13
14
 
14
15
  statics: {
15
16
  createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
package/es/IndexRoute.js CHANGED
@@ -11,6 +11,7 @@ import { component, components, falsy } from './InternalPropTypes';
11
11
  */
12
12
  /* eslint-disable react/require-render-return */
13
13
  var IndexRoute = createReactClass({
14
+ displayName: 'IndexRoute',
14
15
 
15
16
  statics: {
16
17
  createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
package/es/Link.js CHANGED
@@ -42,6 +42,7 @@ function resolveToLocation(to, router) {
42
42
  * <Link to={`/posts/${post.id}`} />
43
43
  */
44
44
  var Link = createReactClass({
45
+ displayName: 'Link',
45
46
 
46
47
  mixins: [ContextSubscriber('router')],
47
48
 
package/es/Redirect.js CHANGED
@@ -14,6 +14,7 @@ import { falsy } from './InternalPropTypes';
14
14
  */
15
15
  /* eslint-disable react/require-render-return */
16
16
  var Redirect = createReactClass({
17
+ displayName: 'Redirect',
17
18
 
18
19
  statics: {
19
20
  createRouteFromReactElement: function createRouteFromReactElement(element) {
package/es/Route.js CHANGED
@@ -16,6 +16,7 @@ import { component, components } from './InternalPropTypes';
16
16
  */
17
17
  /* eslint-disable react/require-render-return */
18
18
  var Route = createReactClass({
19
+ displayName: 'Route',
19
20
 
20
21
  statics: {
21
22
  createRouteFromReactElement: createRouteFromReactElement
package/es/Router.js CHANGED
@@ -33,6 +33,7 @@ var propTypes = {
33
33
  * it needs each time the URL changes.
34
34
  */
35
35
  var Router = createReactClass({
36
+ displayName: 'Router',
36
37
 
37
38
  propTypes: propTypes,
38
39
 
@@ -16,6 +16,7 @@ import { isReactChildren } from './RouteUtils';
16
16
  * and sets the history object and the current location in context.
17
17
  */
18
18
  var RouterContext = createReactClass({
19
+ displayName: 'RouterContext',
19
20
 
20
21
  mixins: [ContextProvider('router')],
21
22
 
@@ -28,121 +28,129 @@ var PendingHooks = function PendingHooks() {
28
28
  };
29
29
  };
30
30
 
31
- var enterHooks = new PendingHooks();
32
- var changeHooks = new PendingHooks();
31
+ export default function getTransitionUtils() {
32
+ var enterHooks = new PendingHooks();
33
+ var changeHooks = new PendingHooks();
33
34
 
34
- function createTransitionHook(hook, route, asyncArity, pendingHooks) {
35
- var isSync = hook.length < asyncArity;
35
+ function createTransitionHook(hook, route, asyncArity, pendingHooks) {
36
+ var isSync = hook.length < asyncArity;
36
37
 
37
- var transitionHook = function transitionHook() {
38
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
39
- args[_key] = arguments[_key];
40
- }
38
+ var transitionHook = function transitionHook() {
39
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
40
+ args[_key] = arguments[_key];
41
+ }
41
42
 
42
- hook.apply(route, args);
43
+ hook.apply(route, args);
43
44
 
44
- if (isSync) {
45
- var callback = args[args.length - 1];
46
- // Assume hook executes synchronously and
47
- // automatically call the callback.
45
+ if (isSync) {
46
+ var callback = args[args.length - 1];
47
+ // Assume hook executes synchronously and
48
+ // automatically call the callback.
49
+ callback();
50
+ }
51
+ };
52
+
53
+ pendingHooks.add(transitionHook);
54
+
55
+ return transitionHook;
56
+ }
57
+
58
+ function getEnterHooks(routes) {
59
+ return routes.reduce(function (hooks, route) {
60
+ if (route.onEnter) hooks.push(createTransitionHook(route.onEnter, route, 3, enterHooks));
61
+ return hooks;
62
+ }, []);
63
+ }
64
+
65
+ function getChangeHooks(routes) {
66
+ return routes.reduce(function (hooks, route) {
67
+ if (route.onChange) hooks.push(createTransitionHook(route.onChange, route, 4, changeHooks));
68
+ return hooks;
69
+ }, []);
70
+ }
71
+
72
+ function runTransitionHooks(length, iter, callback) {
73
+ if (!length) {
48
74
  callback();
75
+ return;
49
76
  }
50
- };
51
77
 
52
- pendingHooks.add(transitionHook);
53
-
54
- return transitionHook;
55
- }
56
-
57
- function getEnterHooks(routes) {
58
- return routes.reduce(function (hooks, route) {
59
- if (route.onEnter) hooks.push(createTransitionHook(route.onEnter, route, 3, enterHooks));
60
- return hooks;
61
- }, []);
62
- }
63
-
64
- function getChangeHooks(routes) {
65
- return routes.reduce(function (hooks, route) {
66
- if (route.onChange) hooks.push(createTransitionHook(route.onChange, route, 4, changeHooks));
67
- return hooks;
68
- }, []);
69
- }
70
-
71
- function runTransitionHooks(length, iter, callback) {
72
- if (!length) {
73
- callback();
74
- return;
78
+ var redirectInfo = void 0;
79
+ function replace(location) {
80
+ redirectInfo = location;
81
+ }
82
+
83
+ loopAsync(length, function (index, next, done) {
84
+ iter(index, replace, function (error) {
85
+ if (error || redirectInfo) {
86
+ done(error, redirectInfo); // No need to continue.
87
+ } else {
88
+ next();
89
+ }
90
+ });
91
+ }, callback);
75
92
  }
76
93
 
77
- var redirectInfo = void 0;
78
- function replace(location) {
79
- redirectInfo = location;
94
+ /**
95
+ * Runs all onEnter hooks in the given array of routes in order
96
+ * with onEnter(nextState, replace, callback) and calls
97
+ * callback(error, redirectInfo) when finished. The first hook
98
+ * to use replace short-circuits the loop.
99
+ *
100
+ * If a hook needs to run asynchronously, it may use the callback
101
+ * function. However, doing so will cause the transition to pause,
102
+ * which could lead to a non-responsive UI if the hook is slow.
103
+ */
104
+ function runEnterHooks(routes, nextState, callback) {
105
+ enterHooks.clear();
106
+ var hooks = getEnterHooks(routes);
107
+ return runTransitionHooks(hooks.length, function (index, replace, next) {
108
+ var wrappedNext = function wrappedNext() {
109
+ if (enterHooks.has(hooks[index])) {
110
+ next.apply(undefined, arguments);
111
+ enterHooks.remove(hooks[index]);
112
+ }
113
+ };
114
+ hooks[index](nextState, replace, wrappedNext);
115
+ }, callback);
80
116
  }
81
117
 
82
- loopAsync(length, function (index, next, done) {
83
- iter(index, replace, function (error) {
84
- if (error || redirectInfo) {
85
- done(error, redirectInfo); // No need to continue.
86
- } else {
87
- next();
88
- }
89
- });
90
- }, callback);
91
- }
92
-
93
- /**
94
- * Runs all onEnter hooks in the given array of routes in order
95
- * with onEnter(nextState, replace, callback) and calls
96
- * callback(error, redirectInfo) when finished. The first hook
97
- * to use replace short-circuits the loop.
98
- *
99
- * If a hook needs to run asynchronously, it may use the callback
100
- * function. However, doing so will cause the transition to pause,
101
- * which could lead to a non-responsive UI if the hook is slow.
102
- */
103
- export function runEnterHooks(routes, nextState, callback) {
104
- enterHooks.clear();
105
- var hooks = getEnterHooks(routes);
106
- return runTransitionHooks(hooks.length, function (index, replace, next) {
107
- var wrappedNext = function wrappedNext() {
108
- if (enterHooks.has(hooks[index])) {
109
- next.apply(undefined, arguments);
110
- enterHooks.remove(hooks[index]);
111
- }
112
- };
113
- hooks[index](nextState, replace, wrappedNext);
114
- }, callback);
115
- }
116
-
117
- /**
118
- * Runs all onChange hooks in the given array of routes in order
119
- * with onChange(prevState, nextState, replace, callback) and calls
120
- * callback(error, redirectInfo) when finished. The first hook
121
- * to use replace short-circuits the loop.
122
- *
123
- * If a hook needs to run asynchronously, it may use the callback
124
- * function. However, doing so will cause the transition to pause,
125
- * which could lead to a non-responsive UI if the hook is slow.
126
- */
127
- export function runChangeHooks(routes, state, nextState, callback) {
128
- changeHooks.clear();
129
- var hooks = getChangeHooks(routes);
130
- return runTransitionHooks(hooks.length, function (index, replace, next) {
131
- var wrappedNext = function wrappedNext() {
132
- if (changeHooks.has(hooks[index])) {
133
- next.apply(undefined, arguments);
134
- changeHooks.remove(hooks[index]);
135
- }
136
- };
137
- hooks[index](state, nextState, replace, wrappedNext);
138
- }, callback);
139
- }
140
-
141
- /**
142
- * Runs all onLeave hooks in the given array of routes in order.
143
- */
144
- export function runLeaveHooks(routes, prevState) {
145
- for (var i = 0, len = routes.length; i < len; ++i) {
146
- if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
118
+ /**
119
+ * Runs all onChange hooks in the given array of routes in order
120
+ * with onChange(prevState, nextState, replace, callback) and calls
121
+ * callback(error, redirectInfo) when finished. The first hook
122
+ * to use replace short-circuits the loop.
123
+ *
124
+ * If a hook needs to run asynchronously, it may use the callback
125
+ * function. However, doing so will cause the transition to pause,
126
+ * which could lead to a non-responsive UI if the hook is slow.
127
+ */
128
+ function runChangeHooks(routes, state, nextState, callback) {
129
+ changeHooks.clear();
130
+ var hooks = getChangeHooks(routes);
131
+ return runTransitionHooks(hooks.length, function (index, replace, next) {
132
+ var wrappedNext = function wrappedNext() {
133
+ if (changeHooks.has(hooks[index])) {
134
+ next.apply(undefined, arguments);
135
+ changeHooks.remove(hooks[index]);
136
+ }
137
+ };
138
+ hooks[index](state, nextState, replace, wrappedNext);
139
+ }, callback);
140
+ }
141
+
142
+ /**
143
+ * Runs all onLeave hooks in the given array of routes in order.
144
+ */
145
+ function runLeaveHooks(routes, prevState) {
146
+ for (var i = 0, len = routes.length; i < len; ++i) {
147
+ if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
148
+ }
147
149
  }
150
+
151
+ return {
152
+ runEnterHooks: runEnterHooks,
153
+ runChangeHooks: runChangeHooks,
154
+ runLeaveHooks: runLeaveHooks
155
+ };
148
156
  }
@@ -2,7 +2,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
2
2
 
3
3
  import warning from './routerWarning';
4
4
  import computeChangedRoutes from './computeChangedRoutes';
5
- import { runEnterHooks, runChangeHooks, runLeaveHooks } from './TransitionUtils';
5
+ import getTransitionUtils from './TransitionUtils';
6
6
  import _isActive from './isActive';
7
7
  import getComponents from './getComponents';
8
8
  import matchRoutes from './matchRoutes';
@@ -16,8 +16,15 @@ function hasAnyProperties(object) {
16
16
  export default function createTransitionManager(history, routes) {
17
17
  var state = {};
18
18
 
19
+ var _getTransitionUtils = getTransitionUtils(),
20
+ runEnterHooks = _getTransitionUtils.runEnterHooks,
21
+ runChangeHooks = _getTransitionUtils.runChangeHooks,
22
+ runLeaveHooks = _getTransitionUtils.runLeaveHooks;
23
+
19
24
  // Signature should be (location, indexOnly), but needs to support (path,
20
25
  // query, indexOnly)
26
+
27
+
21
28
  function isActive(location, indexOnly) {
22
29
  location = history.createLocation(location);
23
30
 
package/es/withRouter.js CHANGED
@@ -15,6 +15,8 @@ export default function withRouter(WrappedComponent, options) {
15
15
  var withRef = options && options.withRef;
16
16
 
17
17
  var WithRouter = createReactClass({
18
+ displayName: 'WithRouter',
19
+
18
20
  mixins: [ContextSubscriber('router')],
19
21
 
20
22
  contextTypes: { router: routerShape },
package/lib/IndexLink.js CHANGED
@@ -22,6 +22,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
22
22
  * An <IndexLink> is used to link to an <IndexRoute>.
23
23
  */
24
24
  var IndexLink = (0, _createReactClass2.default)({
25
+ displayName: 'IndexLink',
26
+
25
27
  render: function render() {
26
28
  return _react2.default.createElement(_Link2.default, _extends({}, this.props, { onlyActiveOnIndex: true }));
27
29
  }
@@ -29,6 +29,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
29
29
  */
30
30
  /* eslint-disable react/require-render-return */
31
31
  var IndexRedirect = (0, _createReactClass2.default)({
32
+ displayName: 'IndexRedirect',
32
33
 
33
34
  statics: {
34
35
  createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
package/lib/IndexRoute.js CHANGED
@@ -28,6 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
28
28
  */
29
29
  /* eslint-disable react/require-render-return */
30
30
  var IndexRoute = (0, _createReactClass2.default)({
31
+ displayName: 'IndexRoute',
31
32
 
32
33
  statics: {
33
34
  createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
package/lib/Link.js CHANGED
@@ -59,6 +59,7 @@ function resolveToLocation(to, router) {
59
59
  * <Link to={`/posts/${post.id}`} />
60
60
  */
61
61
  var Link = (0, _createReactClass2.default)({
62
+ displayName: 'Link',
62
63
 
63
64
  mixins: [(0, _ContextUtils.ContextSubscriber)('router')],
64
65
 
package/lib/Redirect.js CHANGED
@@ -29,6 +29,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
29
29
  */
30
30
  /* eslint-disable react/require-render-return */
31
31
  var Redirect = (0, _createReactClass2.default)({
32
+ displayName: 'Redirect',
32
33
 
33
34
  statics: {
34
35
  createRouteFromReactElement: function createRouteFromReactElement(element) {
package/lib/Route.js CHANGED
@@ -30,6 +30,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
30
30
  */
31
31
  /* eslint-disable react/require-render-return */
32
32
  var Route = (0, _createReactClass2.default)({
33
+ displayName: 'Route',
33
34
 
34
35
  statics: {
35
36
  createRouteFromReactElement: _RouteUtils.createRouteFromReactElement
package/lib/Router.js CHANGED
@@ -59,6 +59,7 @@ var propTypes = {
59
59
  * it needs each time the URL changes.
60
60
  */
61
61
  var Router = (0, _createReactClass2.default)({
62
+ displayName: 'Router',
62
63
 
63
64
  propTypes: propTypes,
64
65
 
@@ -35,6 +35,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
35
35
  * and sets the history object and the current location in context.
36
36
  */
37
37
  var RouterContext = (0, _createReactClass2.default)({
38
+ displayName: 'RouterContext',
38
39
 
39
40
  mixins: [(0, _ContextUtils.ContextProvider)('router')],
40
41