UNPKG

react-router

Version:

A complete routing library for React

46 lines (34 loc) 1.34 kB
'use strict'; exports.__esModule = true; var _AsyncUtils = require('./AsyncUtils'); var _makeStateWithLocation = require('./makeStateWithLocation'); var _makeStateWithLocation2 = _interopRequireDefault(_makeStateWithLocation); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function getComponentsForRoute(nextState, route, callback) { if (route.component || route.components) { callback(null, route.component || route.components); return; } var getComponent = route.getComponent || route.getComponents; if (!getComponent) { callback(); return; } var location = nextState.location; var nextStateWithLocation = (0, _makeStateWithLocation2.default)(nextState, location); getComponent.call(route, nextStateWithLocation, 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) { (0, _AsyncUtils.mapAsync)(nextState.routes, function (route, index, callback) { getComponentsForRoute(nextState, route, callback); }, callback); } exports.default = getComponents; module.exports = exports['default'];