Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/router / src / __unused / matchRouteParams.ts
Size: Mime:
import { isObj } from 'exotic'
import matchPath from 'react-router-dom/matchPath'
import { routePathsList, routePathCurrent } from './routes'
// @TODO @FIXME some issue with import order
// import routes from 'bootstrapper/routes'

/**
 * @description what this does is match our params in bootstrapper/routes
 * @param {*} pathname
 */
function matchRouteParams(pathname) {
  let matched = {}

  // go through our routes
  // use the sealed object for perf
  // match params (which has a cache)
  // merge with matched object
  // return matched
  for (let index = 0; index < routePathsList.length; index++) {
    const matchablePath = routePathsList[index]

    routePathCurrent.path = matchablePath
    const matchedFromPath = matchPath(pathname, routePathCurrent)

    if (isObj(matchedFromPath)) {
      // this.log(pathname, { routePathCurrent, matchedFromPath, pathname })
      Object.assign(matched, matchedFromPath.params)

      // access to which route had the data
      // Object.defineProperty(matched, '@@matches', {
      //   writable: false,
      //   configurable: false,
      //   enumerable: false,
      //   value: matchedFromPath,
      // })
    }
  }

  // if (this.props && isObj(this.props.match)) {
  //   matched = {
  //     ...matched,
  //     ...this.props.match,
  //     ...this.props.match.params,
  //   }
  // } else {
  //   matched.match = matched
  // }
}

export {
  matchRouteParams,
  // routePathsList,
}