all files / modules/ getComponents.js

86.67% Statements 13/15
80% Branches 8/10
100% Functions 3/3
83.33% Lines 10/12
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 27 28 29 30    168× 103× 65×   65×     65×                     86× 168×            
import { mapAsync } from './AsyncUtils'
 
function getComponentsForRoute(location, route, callback) {
  if (route.component || route.components) {
    callback(null, route.component || route.components)
  } else Iif (route.getComponent) {
    route.getComponent(location, callback)
  } else Iif (route.getComponents) {
    route.getComponents(location, 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(nextState.location, route, callback)
  }, callback)
}
 
export default getComponents