{"ast":null,"code":"function _typeof(obj) {\n  if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") {\n    _typeof = function _typeof(obj) {\n      return typeof obj;\n    };\n  } else {\n    _typeof = function _typeof(obj) {\n      return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n    };\n  }\n\n  return _typeof(obj);\n}\n\nimport { matchPath } from \"react-router\";\n\nvar createSelectors = function createSelectors(structure) {\n  var getIn = structure.getIn,\n      toJS = structure.toJS;\n\n  var isRouter = function isRouter(value) {\n    return value != null && _typeof(value) === 'object' && getIn(value, ['location']) && getIn(value, ['action']);\n  };\n\n  var getRouter = function getRouter(state) {\n    var router = toJS(getIn(state, ['router']));\n\n    if (!isRouter(router)) {\n      throw 'Could not find router reducer in state tree, it must be mounted under \"router\"';\n    }\n\n    return router;\n  };\n\n  var getLocation = function getLocation(state) {\n    return toJS(getIn(getRouter(state), ['location']));\n  };\n\n  var getAction = function getAction(state) {\n    return toJS(getIn(getRouter(state), ['action']));\n  };\n\n  var getSearch = function getSearch(state) {\n    return toJS(getIn(getRouter(state), ['location', 'search']));\n  };\n\n  var getHash = function getHash(state) {\n    return toJS(getIn(getRouter(state), ['location', 'hash']));\n  }; // It only makes sense to recalculate the `matchPath` whenever the pathname\n  // of the location changes. That's why `createMatchSelector` memoizes\n  // the latest result based on the location's pathname.\n\n\n  var createMatchSelector = function createMatchSelector(path) {\n    var lastPathname = null;\n    var lastMatch = null;\n    return function (state) {\n      var _ref = getLocation(state) || {},\n          pathname = _ref.pathname;\n\n      if (pathname === lastPathname) {\n        return lastMatch;\n      }\n\n      lastPathname = pathname;\n      var match = matchPath(pathname, path);\n\n      if (!match || !lastMatch || match.url !== lastMatch.url) {\n        lastMatch = match;\n      }\n\n      return lastMatch;\n    };\n  };\n\n  return {\n    getLocation: getLocation,\n    getAction: getAction,\n    getRouter: getRouter,\n    getSearch: getSearch,\n    getHash: getHash,\n    createMatchSelector: createMatchSelector\n  };\n};\n\nexport default createSelectors;","map":null,"metadata":{},"sourceType":"module"}