@tanstack/router-core 0.0.1-alpha.4 → 0.0.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -968,6 +968,7 @@ function createRouter(userOptions) {
968
968
  let router = {
969
969
  options: originalOptions,
970
970
  listeners: [],
971
+ removeActionQueue: [],
971
972
  // Resolved after construction
972
973
  basepath: '',
973
974
  routeTree: undefined,
@@ -1091,12 +1092,14 @@ function createRouter(userOptions) {
1091
1092
  strictParseParams: true
1092
1093
  });
1093
1094
  const toMatches = router.matchRoutes(pathname);
1094
- const prevParams = (_last = last(fromMatches)) == null ? void 0 : _last.params;
1095
+
1096
+ const prevParams = _extends$1({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
1097
+
1095
1098
  let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
1096
1099
 
1097
1100
  if (nextParams) {
1098
1101
  toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
1099
- Object.assign(nextParams, fn(nextParams));
1102
+ Object.assign({}, nextParams, fn(nextParams));
1100
1103
  });
1101
1104
  }
1102
1105
 
@@ -1199,22 +1202,33 @@ function createRouter(userOptions) {
1199
1202
  router.startedLoadingAt = id;
1200
1203
 
1201
1204
  if (next) {
1205
+ // If the location.href has changed
1202
1206
  // Ingest the new location
1203
1207
  router.location = next;
1204
- } // Cancel any pending matches
1208
+ } // Clear out old actions
1205
1209
 
1206
1210
 
1211
+ router.removeActionQueue.forEach(_ref => {
1212
+ let {
1213
+ action,
1214
+ actionState
1215
+ } = _ref;
1216
+
1217
+ if (router.state.currentAction === actionState) {
1218
+ router.state.currentAction = undefined;
1219
+ }
1220
+
1221
+ if (action.current === actionState) {
1222
+ action.current = undefined;
1223
+ }
1224
+ });
1225
+ router.removeActionQueue = []; // Cancel any pending matches
1226
+
1207
1227
  router.cancelMatches(); // Match the routes
1208
1228
 
1209
1229
  const unloadedMatches = router.matchRoutes(location.pathname, {
1210
1230
  strictParseParams: true
1211
1231
  });
1212
- unloadedMatches.forEach((match, index) => {
1213
- const parent = unloadedMatches[index - 1];
1214
- const child = unloadedMatches[index + 1];
1215
- if (parent) match.__.setParentMatch(parent);
1216
- if (child) match.__.addChildMatch(child);
1217
- });
1218
1232
  router.state = _extends$1({}, router.state, {
1219
1233
  pending: {
1220
1234
  matches: unloadedMatches,
@@ -1395,6 +1409,7 @@ function createRouter(userOptions) {
1395
1409
  };
1396
1410
 
1397
1411
  recurse([router.routeTree]);
1412
+ cascadeLoaderData(matches);
1398
1413
  return matches;
1399
1414
  },
1400
1415
  loadMatches: async (resolvedMatches, loaderOpts) => {
@@ -1473,14 +1488,14 @@ function createRouter(userOptions) {
1473
1488
  const next = router.buildNext(location);
1474
1489
  return router.commitLocation(next, location.replace);
1475
1490
  },
1476
- navigate: async _ref => {
1491
+ navigate: async _ref2 => {
1477
1492
  let {
1478
1493
  from,
1479
1494
  to = '.',
1480
1495
  search,
1481
1496
  hash,
1482
1497
  replace
1483
- } = _ref;
1498
+ } = _ref2;
1484
1499
  // If this link simply reloads the current route,
1485
1500
  // make sure it has a new key so it will trigger a data refresh
1486
1501
  // If this `to` is a valid external URL, return
@@ -1502,8 +1517,8 @@ function createRouter(userOptions) {
1502
1517
  hash
1503
1518
  });
1504
1519
  },
1505
- buildLink: _ref2 => {
1506
- var _preload, _ref3, _ref4;
1520
+ buildLink: _ref3 => {
1521
+ var _preload, _ref4, _ref5;
1507
1522
 
1508
1523
  let {
1509
1524
  from,
@@ -1518,7 +1533,7 @@ function createRouter(userOptions) {
1518
1533
  preloadMaxAge: userPreloadMaxAge,
1519
1534
  preloadDelay: userPreloadDelay,
1520
1535
  disabled
1521
- } = _ref2;
1536
+ } = _ref3;
1522
1537
 
1523
1538
  // If this link simply reloads the current route,
1524
1539
  // make sure it has a new key so it will trigger a data refresh
@@ -1542,8 +1557,8 @@ function createRouter(userOptions) {
1542
1557
  };
1543
1558
  const next = router.buildNext(nextOpts);
1544
1559
  preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
1545
- const preloadMaxAge = (_ref3 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref3 : 2000;
1546
- const preloadDelay = (_ref4 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref4 : 50; // Compare path/hash for matches
1560
+ const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
1561
+ const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
1547
1562
 
1548
1563
  const pathIsEqual = router.state.location.pathname === next.pathname;
1549
1564
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -1617,11 +1632,11 @@ function createRouter(userOptions) {
1617
1632
  },
1618
1633
  __experimental__createSnapshot: () => {
1619
1634
  return _extends$1({}, router.state, {
1620
- matches: router.state.matches.map(_ref5 => {
1635
+ matches: router.state.matches.map(_ref6 => {
1621
1636
  let {
1622
1637
  routeLoaderData: loaderData,
1623
1638
  matchId
1624
- } = _ref5;
1639
+ } = _ref6;
1625
1640
  return {
1626
1641
  matchId,
1627
1642
  loaderData
@@ -1671,10 +1686,12 @@ function createRoute(routeConfig, options, parent, router) {
1671
1686
  status: 'pending',
1672
1687
  submission
1673
1688
  };
1689
+ action.current = actionState;
1674
1690
  action.latest = actionState;
1675
1691
  action.pending.push(actionState);
1676
1692
  router.state = _extends$1({}, router.state, {
1677
- action: actionState
1693
+ currentAction: actionState,
1694
+ latestAction: actionState
1678
1695
  });
1679
1696
  router.notify();
1680
1697
 
@@ -1698,11 +1715,10 @@ function createRoute(routeConfig, options, parent, router) {
1698
1715
  actionState.status = 'error';
1699
1716
  } finally {
1700
1717
  action.pending = action.pending.filter(d => d !== actionState);
1701
-
1702
- if (actionState === router.state.action) {
1703
- router.state.action = undefined;
1704
- }
1705
-
1718
+ router.removeActionQueue.push({
1719
+ action,
1720
+ actionState
1721
+ });
1706
1722
  router.notify();
1707
1723
  }
1708
1724
  }
@@ -1789,16 +1805,17 @@ function createRouteMatch(router, route, opts) {
1789
1805
  clearTimeout(routeMatch.__.pendingMinTimeout);
1790
1806
  delete routeMatch.__.pendingMinPromise;
1791
1807
  },
1792
- setParentMatch: parentMatch => {
1793
- routeMatch.parentMatch = parentMatch;
1794
- },
1795
- addChildMatch: childMatch => {
1796
- if (routeMatch.childMatches.find(d => d.matchId === childMatch.matchId)) {
1797
- return;
1798
- }
1799
-
1800
- routeMatch.childMatches.push(childMatch);
1801
- },
1808
+ // setParentMatch: (parentMatch?: RouteMatch) => {
1809
+ // routeMatch.parentMatch = parentMatch
1810
+ // },
1811
+ // addChildMatch: (childMatch: RouteMatch) => {
1812
+ // if (
1813
+ // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
1814
+ // ) {
1815
+ // return
1816
+ // }
1817
+ // routeMatch.childMatches.push(childMatch)
1818
+ // },
1802
1819
  validate: () => {
1803
1820
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1804
1821
 
@@ -1902,7 +1919,6 @@ function createRouteMatch(router, route, opts) {
1902
1919
  }
1903
1920
 
1904
1921
  routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1905
- cascadeLoaderData(routeMatch);
1906
1922
  routeMatch.error = undefined;
1907
1923
  routeMatch.status = 'success';
1908
1924
  routeMatch.updatedAt = Date.now();
@@ -1962,16 +1978,14 @@ function createRouteMatch(router, route, opts) {
1962
1978
  return routeMatch;
1963
1979
  }
1964
1980
 
1965
- function cascadeLoaderData(routeMatch) {
1966
- if (routeMatch.parentMatch) {
1967
- routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, _extends$1({}, routeMatch.parentMatch.loaderData, routeMatch.routeLoaderData));
1968
- }
1981
+ function cascadeLoaderData(matches) {
1982
+ matches.forEach((match, index) => {
1983
+ const parent = matches[index - 1];
1969
1984
 
1970
- if (routeMatch.childMatches.length) {
1971
- routeMatch.childMatches.forEach(childMatch => {
1972
- cascadeLoaderData(childMatch);
1973
- });
1974
- }
1985
+ if (parent) {
1986
+ match.loaderData = replaceEqualDeep(match.loaderData, _extends$1({}, parent.loaderData, match.routeLoaderData));
1987
+ }
1988
+ });
1975
1989
  }
1976
1990
 
1977
1991
  function matchPathname(currentPathname, matchLocation) {