import { routes } from './config-routes.js'
import { connect } from 'react-redux'

export const path = Object.keys(routes).reduce((mapping, route) => {
  mapping[route] = routes[route].pattern
  return mapping
}, {})

export const paramsToProps = Object.keys(routes).reduce((mapping, route) => {
  mapping[routes[route].pattern] = (state, { routeParams }) => 
    routes[route].paramsToProps(state, routeParams)
  return mapping
}, {})

export const uriToLink = Object.keys(routes).reduce((mapping, route) => {
  mapping[route] = routes[route].uriToLink
  return mapping
}, {})

export const connectFromRoute = (...args) => connect(
  (state, ownProps) => {
    const mapRoute = paramsToProps[ownProps.route.path]
    //TODO warning if no mapping is found for the route (because it fails
    //silently but it can hide an error)
    return mapRoute ? mapRoute(state, ownProps) : {}
  })(...args)




@@ -715,117 +715,129 @@
     
-//TODO warning if no mapping is found for the route (because it fails%0A    //silently but it can hide an error
+if (mapRoute === undefined) throw new ReferenceError(%0A      %60Mapping for route %5C%60$%7BownProps.route.path%7D%5C%60is missing%60%0A    
 )%0A  

Throw error where no mapping was found for a route