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

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
 
@@ -1201,20 +1204,30 @@ function createRouter(userOptions) {
1201
1204
  if (next) {
1202
1205
  // Ingest the new location
1203
1206
  router.location = next;
1204
- } // Cancel any pending matches
1207
+ } // Clear out old actions
1208
+
1209
+
1210
+ router.removeActionQueue.forEach(_ref => {
1211
+ let {
1212
+ action,
1213
+ actionState
1214
+ } = _ref;
1205
1215
 
1216
+ if (router.state.currentAction === actionState) {
1217
+ router.state.currentAction = undefined;
1218
+ }
1219
+
1220
+ if (action.current === actionState) {
1221
+ action.current = undefined;
1222
+ }
1223
+ });
1224
+ router.removeActionQueue = []; // Cancel any pending matches
1206
1225
 
1207
1226
  router.cancelMatches(); // Match the routes
1208
1227
 
1209
1228
  const unloadedMatches = router.matchRoutes(location.pathname, {
1210
1229
  strictParseParams: true
1211
1230
  });
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
1231
  router.state = _extends$1({}, router.state, {
1219
1232
  pending: {
1220
1233
  matches: unloadedMatches,
@@ -1395,6 +1408,7 @@ function createRouter(userOptions) {
1395
1408
  };
1396
1409
 
1397
1410
  recurse([router.routeTree]);
1411
+ cascadeLoaderData(matches);
1398
1412
  return matches;
1399
1413
  },
1400
1414
  loadMatches: async (resolvedMatches, loaderOpts) => {
@@ -1432,7 +1446,7 @@ function createRouter(userOptions) {
1432
1446
  const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
1433
1447
  [...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
1434
1448
  if (unloadedMatchIds.includes(match.matchId)) {
1435
- match.isInvalid = true;
1449
+ match.invalidate();
1436
1450
  }
1437
1451
  });
1438
1452
  },
@@ -1473,14 +1487,15 @@ function createRouter(userOptions) {
1473
1487
  const next = router.buildNext(location);
1474
1488
  return router.commitLocation(next, location.replace);
1475
1489
  },
1476
- navigate: async _ref => {
1490
+ navigate: async _ref2 => {
1477
1491
  let {
1478
1492
  from,
1479
1493
  to = '.',
1480
1494
  search,
1481
1495
  hash,
1482
- replace
1483
- } = _ref;
1496
+ replace,
1497
+ params
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
@@ -1499,11 +1514,13 @@ function createRouter(userOptions) {
1499
1514
  from: fromString,
1500
1515
  to: toString,
1501
1516
  search,
1502
- hash
1517
+ hash,
1518
+ replace,
1519
+ params
1503
1520
  });
1504
1521
  },
1505
- buildLink: _ref2 => {
1506
- var _preload, _ref3, _ref4;
1522
+ buildLink: _ref3 => {
1523
+ var _preload, _ref4, _ref5;
1507
1524
 
1508
1525
  let {
1509
1526
  from,
@@ -1518,7 +1535,7 @@ function createRouter(userOptions) {
1518
1535
  preloadMaxAge: userPreloadMaxAge,
1519
1536
  preloadDelay: userPreloadDelay,
1520
1537
  disabled
1521
- } = _ref2;
1538
+ } = _ref3;
1522
1539
 
1523
1540
  // If this link simply reloads the current route,
1524
1541
  // make sure it has a new key so it will trigger a data refresh
@@ -1542,8 +1559,8 @@ function createRouter(userOptions) {
1542
1559
  };
1543
1560
  const next = router.buildNext(nextOpts);
1544
1561
  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
1562
+ const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
1563
+ const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
1547
1564
 
1548
1565
  const pathIsEqual = router.state.location.pathname === next.pathname;
1549
1566
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -1617,11 +1634,11 @@ function createRouter(userOptions) {
1617
1634
  },
1618
1635
  __experimental__createSnapshot: () => {
1619
1636
  return _extends$1({}, router.state, {
1620
- matches: router.state.matches.map(_ref5 => {
1637
+ matches: router.state.matches.map(_ref6 => {
1621
1638
  let {
1622
1639
  routeLoaderData: loaderData,
1623
1640
  matchId
1624
- } = _ref5;
1641
+ } = _ref6;
1625
1642
  return {
1626
1643
  matchId,
1627
1644
  loaderData
@@ -1671,10 +1688,12 @@ function createRoute(routeConfig, options, parent, router) {
1671
1688
  status: 'pending',
1672
1689
  submission
1673
1690
  };
1691
+ action.current = actionState;
1674
1692
  action.latest = actionState;
1675
1693
  action.pending.push(actionState);
1676
1694
  router.state = _extends$1({}, router.state, {
1677
- action: actionState
1695
+ currentAction: actionState,
1696
+ latestAction: actionState
1678
1697
  });
1679
1698
  router.notify();
1680
1699
 
@@ -1698,11 +1717,10 @@ function createRoute(routeConfig, options, parent, router) {
1698
1717
  actionState.status = 'error';
1699
1718
  } finally {
1700
1719
  action.pending = action.pending.filter(d => d !== actionState);
1701
-
1702
- if (actionState === router.state.action) {
1703
- router.state.action = undefined;
1704
- }
1705
-
1720
+ router.removeActionQueue.push({
1721
+ action,
1722
+ actionState
1723
+ });
1706
1724
  router.notify();
1707
1725
  }
1708
1726
  }
@@ -1789,16 +1807,17 @@ function createRouteMatch(router, route, opts) {
1789
1807
  clearTimeout(routeMatch.__.pendingMinTimeout);
1790
1808
  delete routeMatch.__.pendingMinPromise;
1791
1809
  },
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
- },
1810
+ // setParentMatch: (parentMatch?: RouteMatch) => {
1811
+ // routeMatch.parentMatch = parentMatch
1812
+ // },
1813
+ // addChildMatch: (childMatch: RouteMatch) => {
1814
+ // if (
1815
+ // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
1816
+ // ) {
1817
+ // return
1818
+ // }
1819
+ // routeMatch.childMatches.push(childMatch)
1820
+ // },
1802
1821
  validate: () => {
1803
1822
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1804
1823
 
@@ -1835,6 +1854,9 @@ function createRouteMatch(router, route, opts) {
1835
1854
 
1836
1855
  routeMatch.__.cancelPending();
1837
1856
  },
1857
+ invalidate: () => {
1858
+ routeMatch.isInvalid = true;
1859
+ },
1838
1860
  load: async () => {
1839
1861
  const id = '' + Date.now() + Math.random();
1840
1862
  routeMatch.__.latestId = id; // If the match was in an error state, set it
@@ -1902,7 +1924,6 @@ function createRouteMatch(router, route, opts) {
1902
1924
  }
1903
1925
 
1904
1926
  routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1905
- cascadeLoaderData(routeMatch);
1906
1927
  routeMatch.error = undefined;
1907
1928
  routeMatch.status = 'success';
1908
1929
  routeMatch.updatedAt = Date.now();
@@ -1962,16 +1983,14 @@ function createRouteMatch(router, route, opts) {
1962
1983
  return routeMatch;
1963
1984
  }
1964
1985
 
1965
- function cascadeLoaderData(routeMatch) {
1966
- if (routeMatch.parentMatch) {
1967
- routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, _extends$1({}, routeMatch.parentMatch.loaderData, routeMatch.routeLoaderData));
1968
- }
1986
+ function cascadeLoaderData(matches) {
1987
+ matches.forEach((match, index) => {
1988
+ const parent = matches[index - 1];
1969
1989
 
1970
- if (routeMatch.childMatches.length) {
1971
- routeMatch.childMatches.forEach(childMatch => {
1972
- cascadeLoaderData(childMatch);
1973
- });
1974
- }
1990
+ if (parent) {
1991
+ match.loaderData = replaceEqualDeep(match.loaderData, _extends$1({}, parent.loaderData, match.routeLoaderData));
1992
+ }
1993
+ });
1975
1994
  }
1976
1995
 
1977
1996
  function matchPathname(currentPathname, matchLocation) {