@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.
- package/build/cjs/packages/router-core/src/index.js +58 -44
- package/build/cjs/packages/router-core/src/index.js.map +1 -1
- package/build/esm/index.js +58 -44
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +42 -42
- package/build/types/index.d.ts +8 -4
- package/build/umd/index.development.js +58 -44
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +51 -43
|
@@ -83,6 +83,7 @@ function createRouter(userOptions) {
|
|
|
83
83
|
let router = {
|
|
84
84
|
options: originalOptions,
|
|
85
85
|
listeners: [],
|
|
86
|
+
removeActionQueue: [],
|
|
86
87
|
// Resolved after construction
|
|
87
88
|
basepath: '',
|
|
88
89
|
routeTree: undefined,
|
|
@@ -206,12 +207,14 @@ function createRouter(userOptions) {
|
|
|
206
207
|
strictParseParams: true
|
|
207
208
|
});
|
|
208
209
|
const toMatches = router.matchRoutes(pathname);
|
|
209
|
-
|
|
210
|
+
|
|
211
|
+
const prevParams = _rollupPluginBabelHelpers["extends"]({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
212
|
+
|
|
210
213
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
211
214
|
|
|
212
215
|
if (nextParams) {
|
|
213
216
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
214
|
-
Object.assign(nextParams, fn(nextParams));
|
|
217
|
+
Object.assign({}, nextParams, fn(nextParams));
|
|
215
218
|
});
|
|
216
219
|
}
|
|
217
220
|
|
|
@@ -314,22 +317,33 @@ function createRouter(userOptions) {
|
|
|
314
317
|
router.startedLoadingAt = id;
|
|
315
318
|
|
|
316
319
|
if (next) {
|
|
320
|
+
// If the location.href has changed
|
|
317
321
|
// Ingest the new location
|
|
318
322
|
router.location = next;
|
|
319
|
-
} //
|
|
323
|
+
} // Clear out old actions
|
|
320
324
|
|
|
321
325
|
|
|
326
|
+
router.removeActionQueue.forEach(_ref => {
|
|
327
|
+
let {
|
|
328
|
+
action,
|
|
329
|
+
actionState
|
|
330
|
+
} = _ref;
|
|
331
|
+
|
|
332
|
+
if (router.state.currentAction === actionState) {
|
|
333
|
+
router.state.currentAction = undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (action.current === actionState) {
|
|
337
|
+
action.current = undefined;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
router.removeActionQueue = []; // Cancel any pending matches
|
|
341
|
+
|
|
322
342
|
router.cancelMatches(); // Match the routes
|
|
323
343
|
|
|
324
344
|
const unloadedMatches = router.matchRoutes(location.pathname, {
|
|
325
345
|
strictParseParams: true
|
|
326
346
|
});
|
|
327
|
-
unloadedMatches.forEach((match, index) => {
|
|
328
|
-
const parent = unloadedMatches[index - 1];
|
|
329
|
-
const child = unloadedMatches[index + 1];
|
|
330
|
-
if (parent) match.__.setParentMatch(parent);
|
|
331
|
-
if (child) match.__.addChildMatch(child);
|
|
332
|
-
});
|
|
333
347
|
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
334
348
|
pending: {
|
|
335
349
|
matches: unloadedMatches,
|
|
@@ -510,6 +524,7 @@ function createRouter(userOptions) {
|
|
|
510
524
|
};
|
|
511
525
|
|
|
512
526
|
recurse([router.routeTree]);
|
|
527
|
+
cascadeLoaderData(matches);
|
|
513
528
|
return matches;
|
|
514
529
|
},
|
|
515
530
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
@@ -588,14 +603,14 @@ function createRouter(userOptions) {
|
|
|
588
603
|
const next = router.buildNext(location);
|
|
589
604
|
return router.commitLocation(next, location.replace);
|
|
590
605
|
},
|
|
591
|
-
navigate: async
|
|
606
|
+
navigate: async _ref2 => {
|
|
592
607
|
let {
|
|
593
608
|
from,
|
|
594
609
|
to = '.',
|
|
595
610
|
search,
|
|
596
611
|
hash,
|
|
597
612
|
replace
|
|
598
|
-
} =
|
|
613
|
+
} = _ref2;
|
|
599
614
|
// If this link simply reloads the current route,
|
|
600
615
|
// make sure it has a new key so it will trigger a data refresh
|
|
601
616
|
// If this `to` is a valid external URL, return
|
|
@@ -617,8 +632,8 @@ function createRouter(userOptions) {
|
|
|
617
632
|
hash
|
|
618
633
|
});
|
|
619
634
|
},
|
|
620
|
-
buildLink:
|
|
621
|
-
var _preload,
|
|
635
|
+
buildLink: _ref3 => {
|
|
636
|
+
var _preload, _ref4, _ref5;
|
|
622
637
|
|
|
623
638
|
let {
|
|
624
639
|
from,
|
|
@@ -633,7 +648,7 @@ function createRouter(userOptions) {
|
|
|
633
648
|
preloadMaxAge: userPreloadMaxAge,
|
|
634
649
|
preloadDelay: userPreloadDelay,
|
|
635
650
|
disabled
|
|
636
|
-
} =
|
|
651
|
+
} = _ref3;
|
|
637
652
|
|
|
638
653
|
// If this link simply reloads the current route,
|
|
639
654
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -657,8 +672,8 @@ function createRouter(userOptions) {
|
|
|
657
672
|
};
|
|
658
673
|
const next = router.buildNext(nextOpts);
|
|
659
674
|
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
660
|
-
const preloadMaxAge = (
|
|
661
|
-
const preloadDelay = (
|
|
675
|
+
const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
|
|
676
|
+
const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
|
|
662
677
|
|
|
663
678
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
664
679
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -732,11 +747,11 @@ function createRouter(userOptions) {
|
|
|
732
747
|
},
|
|
733
748
|
__experimental__createSnapshot: () => {
|
|
734
749
|
return _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
735
|
-
matches: router.state.matches.map(
|
|
750
|
+
matches: router.state.matches.map(_ref6 => {
|
|
736
751
|
let {
|
|
737
752
|
routeLoaderData: loaderData,
|
|
738
753
|
matchId
|
|
739
|
-
} =
|
|
754
|
+
} = _ref6;
|
|
740
755
|
return {
|
|
741
756
|
matchId,
|
|
742
757
|
loaderData
|
|
@@ -786,10 +801,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
786
801
|
status: 'pending',
|
|
787
802
|
submission
|
|
788
803
|
};
|
|
804
|
+
action.current = actionState;
|
|
789
805
|
action.latest = actionState;
|
|
790
806
|
action.pending.push(actionState);
|
|
791
807
|
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
792
|
-
|
|
808
|
+
currentAction: actionState,
|
|
809
|
+
latestAction: actionState
|
|
793
810
|
});
|
|
794
811
|
router.notify();
|
|
795
812
|
|
|
@@ -813,11 +830,10 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
813
830
|
actionState.status = 'error';
|
|
814
831
|
} finally {
|
|
815
832
|
action.pending = action.pending.filter(d => d !== actionState);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
|
|
833
|
+
router.removeActionQueue.push({
|
|
834
|
+
action,
|
|
835
|
+
actionState
|
|
836
|
+
});
|
|
821
837
|
router.notify();
|
|
822
838
|
}
|
|
823
839
|
}
|
|
@@ -904,16 +920,17 @@ function createRouteMatch(router, route, opts) {
|
|
|
904
920
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
905
921
|
delete routeMatch.__.pendingMinPromise;
|
|
906
922
|
},
|
|
907
|
-
setParentMatch: parentMatch => {
|
|
908
|
-
|
|
909
|
-
},
|
|
910
|
-
addChildMatch: childMatch => {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
923
|
+
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
924
|
+
// routeMatch.parentMatch = parentMatch
|
|
925
|
+
// },
|
|
926
|
+
// addChildMatch: (childMatch: RouteMatch) => {
|
|
927
|
+
// if (
|
|
928
|
+
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
929
|
+
// ) {
|
|
930
|
+
// return
|
|
931
|
+
// }
|
|
932
|
+
// routeMatch.childMatches.push(childMatch)
|
|
933
|
+
// },
|
|
917
934
|
validate: () => {
|
|
918
935
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
919
936
|
|
|
@@ -1017,7 +1034,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1017
1034
|
}
|
|
1018
1035
|
|
|
1019
1036
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1020
|
-
cascadeLoaderData(routeMatch);
|
|
1021
1037
|
routeMatch.error = undefined;
|
|
1022
1038
|
routeMatch.status = 'success';
|
|
1023
1039
|
routeMatch.updatedAt = Date.now();
|
|
@@ -1077,16 +1093,14 @@ function createRouteMatch(router, route, opts) {
|
|
|
1077
1093
|
return routeMatch;
|
|
1078
1094
|
}
|
|
1079
1095
|
|
|
1080
|
-
function cascadeLoaderData(
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
}
|
|
1096
|
+
function cascadeLoaderData(matches) {
|
|
1097
|
+
matches.forEach((match, index) => {
|
|
1098
|
+
const parent = matches[index - 1];
|
|
1084
1099
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1100
|
+
if (parent) {
|
|
1101
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _rollupPluginBabelHelpers["extends"]({}, parent.loaderData, match.routeLoaderData));
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1090
1104
|
}
|
|
1091
1105
|
|
|
1092
1106
|
function matchPathname(currentPathname, matchLocation) {
|