forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetComponents.js
More file actions
26 lines (23 loc) · 753 Bytes
/
getComponents.js
File metadata and controls
26 lines (23 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { mapAsync } from './AsyncUtils';
function getComponentsForRoute(route, callback) {
if (route.component || route.components) {
callback(null, route.component || route.components);
} else if (route.getComponents) {
route.getComponents(callback);
} else {
callback();
}
}
/**
* Asynchronously fetches all components needed for the given router
* state and calls callback(error, components) when finished.
*
* Note: This operation may finish synchronously if no routes have an
* asynchronous getComponents method.
*/
function getComponents(nextState, callback) {
mapAsync(nextState.routes, function (route, index, callback) {
getComponentsForRoute(route, callback);
}, callback);
}
export default getComponents;