All files / src routeMatcher.js

33.33% Statements 6/18
0% Branches 0/8
0% Functions 0/1
40% Lines 6/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 31 32 33 34 35 36 37 38 39 40 41  1x   1x 1x         1x 1x   1x                                                        
 
import { compose } from 'lodash/fp'
 
import { getProps, wrapChildren } from './utils'
import { DEFAULT_KEY } from './update'
 
// const {matchRoute} = require(`${process.env.BABEL_ENV}/routes.js`)
// const {mapChildren: mapChilds} = require(`${process.env.BABEL_ENV}/component.js`)
 
import { matchRoute } from './env/react/routes'
import { mapChildren as mapChilds } from './env/react/component'
 
export const RouteMatcher = props => {
  const { children, navigation } = getProps({
    ...props,
    root: DEFAULT_KEY
  })
 
  const { mapChildren } = props
 
  if (!navigation) {
    return null
  }
 
  const { stack, index } = navigation
 
  if (!stack || !stack.length) {
    return null
  }
 
  // Invoke the mapper if available
  const childs = mapChildren
    ? mapChilds(children, mapChildren)
    : children
 
  return compose(
    wrapChildren,
    matchRoute(stack[index])
  )(childs)
}