How to use the @mapbox/batfish/modules/route-change-listeners._invokeRouteChangeStartCallbacks function in @mapbox/batfish

To help you get started, we’ve selected a few @mapbox/batfish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapbox / batfish / src / webpack / change-page.js View on Github external
export function changePage(
  nextLocation: BatfishLocation,
  setRouterState: (state: RouterState, callback: () => void) => void,
  options: { pushState?: boolean, scrollToTop?: boolean } = {},
  onFinish?: () => mixed
): Promise {
  const win = getWindow();
  const matchingRoute = findMatchingRoute(nextLocation.pathname);
  const nextUrl = [
    nextLocation.pathname,
    nextLocation.hash,
    nextLocation.search
  ].join('');
  // Call the change-start callbacks immediately, not after the page chunk
  // has already been fetched.
  const startChange = _invokeRouteChangeStartCallbacks(nextLocation.pathname);
  return matchingRoute
    .getPage()
    .then((pageModule) => {
      return startChange.then(() => pageModule);
    })
    .then((pageModule) => {
      if (options.pushState) {
        win.history.pushState({}, null, nextUrl);
      }
      const nextState = {
        path: matchingRoute.path,
        PageComponent: pageModule.component,
        pageProps: pageModule.props,
        location: getCurrentLocation()
      };
      setRouterState(nextState, () => {