@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.
- package/build/cjs/packages/router-core/src/index.js +66 -47
- package/build/cjs/packages/router-core/src/index.js.map +1 -1
- package/build/esm/index.js +66 -47
- 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 +12 -5
- package/build/umd/index.development.js +66 -47
- 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 +60 -46
|
@@ -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
|
|
|
@@ -316,20 +319,30 @@ function createRouter(userOptions) {
|
|
|
316
319
|
if (next) {
|
|
317
320
|
// Ingest the new location
|
|
318
321
|
router.location = next;
|
|
319
|
-
} //
|
|
322
|
+
} // Clear out old actions
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
router.removeActionQueue.forEach(_ref => {
|
|
326
|
+
let {
|
|
327
|
+
action,
|
|
328
|
+
actionState
|
|
329
|
+
} = _ref;
|
|
320
330
|
|
|
331
|
+
if (router.state.currentAction === actionState) {
|
|
332
|
+
router.state.currentAction = undefined;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (action.current === actionState) {
|
|
336
|
+
action.current = undefined;
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
router.removeActionQueue = []; // Cancel any pending matches
|
|
321
340
|
|
|
322
341
|
router.cancelMatches(); // Match the routes
|
|
323
342
|
|
|
324
343
|
const unloadedMatches = router.matchRoutes(location.pathname, {
|
|
325
344
|
strictParseParams: true
|
|
326
345
|
});
|
|
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
346
|
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
334
347
|
pending: {
|
|
335
348
|
matches: unloadedMatches,
|
|
@@ -510,6 +523,7 @@ function createRouter(userOptions) {
|
|
|
510
523
|
};
|
|
511
524
|
|
|
512
525
|
recurse([router.routeTree]);
|
|
526
|
+
cascadeLoaderData(matches);
|
|
513
527
|
return matches;
|
|
514
528
|
},
|
|
515
529
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
@@ -547,7 +561,7 @@ function createRouter(userOptions) {
|
|
|
547
561
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
548
562
|
[...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 => {
|
|
549
563
|
if (unloadedMatchIds.includes(match.matchId)) {
|
|
550
|
-
match.
|
|
564
|
+
match.invalidate();
|
|
551
565
|
}
|
|
552
566
|
});
|
|
553
567
|
},
|
|
@@ -588,14 +602,15 @@ function createRouter(userOptions) {
|
|
|
588
602
|
const next = router.buildNext(location);
|
|
589
603
|
return router.commitLocation(next, location.replace);
|
|
590
604
|
},
|
|
591
|
-
navigate: async
|
|
605
|
+
navigate: async _ref2 => {
|
|
592
606
|
let {
|
|
593
607
|
from,
|
|
594
608
|
to = '.',
|
|
595
609
|
search,
|
|
596
610
|
hash,
|
|
597
|
-
replace
|
|
598
|
-
|
|
611
|
+
replace,
|
|
612
|
+
params
|
|
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
|
|
@@ -614,11 +629,13 @@ function createRouter(userOptions) {
|
|
|
614
629
|
from: fromString,
|
|
615
630
|
to: toString,
|
|
616
631
|
search,
|
|
617
|
-
hash
|
|
632
|
+
hash,
|
|
633
|
+
replace,
|
|
634
|
+
params
|
|
618
635
|
});
|
|
619
636
|
},
|
|
620
|
-
buildLink:
|
|
621
|
-
var _preload,
|
|
637
|
+
buildLink: _ref3 => {
|
|
638
|
+
var _preload, _ref4, _ref5;
|
|
622
639
|
|
|
623
640
|
let {
|
|
624
641
|
from,
|
|
@@ -633,7 +650,7 @@ function createRouter(userOptions) {
|
|
|
633
650
|
preloadMaxAge: userPreloadMaxAge,
|
|
634
651
|
preloadDelay: userPreloadDelay,
|
|
635
652
|
disabled
|
|
636
|
-
} =
|
|
653
|
+
} = _ref3;
|
|
637
654
|
|
|
638
655
|
// If this link simply reloads the current route,
|
|
639
656
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -657,8 +674,8 @@ function createRouter(userOptions) {
|
|
|
657
674
|
};
|
|
658
675
|
const next = router.buildNext(nextOpts);
|
|
659
676
|
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
660
|
-
const preloadMaxAge = (
|
|
661
|
-
const preloadDelay = (
|
|
677
|
+
const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
|
|
678
|
+
const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
|
|
662
679
|
|
|
663
680
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
664
681
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -732,11 +749,11 @@ function createRouter(userOptions) {
|
|
|
732
749
|
},
|
|
733
750
|
__experimental__createSnapshot: () => {
|
|
734
751
|
return _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
735
|
-
matches: router.state.matches.map(
|
|
752
|
+
matches: router.state.matches.map(_ref6 => {
|
|
736
753
|
let {
|
|
737
754
|
routeLoaderData: loaderData,
|
|
738
755
|
matchId
|
|
739
|
-
} =
|
|
756
|
+
} = _ref6;
|
|
740
757
|
return {
|
|
741
758
|
matchId,
|
|
742
759
|
loaderData
|
|
@@ -786,10 +803,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
786
803
|
status: 'pending',
|
|
787
804
|
submission
|
|
788
805
|
};
|
|
806
|
+
action.current = actionState;
|
|
789
807
|
action.latest = actionState;
|
|
790
808
|
action.pending.push(actionState);
|
|
791
809
|
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
792
|
-
|
|
810
|
+
currentAction: actionState,
|
|
811
|
+
latestAction: actionState
|
|
793
812
|
});
|
|
794
813
|
router.notify();
|
|
795
814
|
|
|
@@ -813,11 +832,10 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
813
832
|
actionState.status = 'error';
|
|
814
833
|
} finally {
|
|
815
834
|
action.pending = action.pending.filter(d => d !== actionState);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
|
|
835
|
+
router.removeActionQueue.push({
|
|
836
|
+
action,
|
|
837
|
+
actionState
|
|
838
|
+
});
|
|
821
839
|
router.notify();
|
|
822
840
|
}
|
|
823
841
|
}
|
|
@@ -904,16 +922,17 @@ function createRouteMatch(router, route, opts) {
|
|
|
904
922
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
905
923
|
delete routeMatch.__.pendingMinPromise;
|
|
906
924
|
},
|
|
907
|
-
setParentMatch: parentMatch => {
|
|
908
|
-
|
|
909
|
-
},
|
|
910
|
-
addChildMatch: childMatch => {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
925
|
+
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
926
|
+
// routeMatch.parentMatch = parentMatch
|
|
927
|
+
// },
|
|
928
|
+
// addChildMatch: (childMatch: RouteMatch) => {
|
|
929
|
+
// if (
|
|
930
|
+
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
931
|
+
// ) {
|
|
932
|
+
// return
|
|
933
|
+
// }
|
|
934
|
+
// routeMatch.childMatches.push(childMatch)
|
|
935
|
+
// },
|
|
917
936
|
validate: () => {
|
|
918
937
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
919
938
|
|
|
@@ -950,6 +969,9 @@ function createRouteMatch(router, route, opts) {
|
|
|
950
969
|
|
|
951
970
|
routeMatch.__.cancelPending();
|
|
952
971
|
},
|
|
972
|
+
invalidate: () => {
|
|
973
|
+
routeMatch.isInvalid = true;
|
|
974
|
+
},
|
|
953
975
|
load: async () => {
|
|
954
976
|
const id = '' + Date.now() + Math.random();
|
|
955
977
|
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
@@ -1017,7 +1039,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1017
1039
|
}
|
|
1018
1040
|
|
|
1019
1041
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1020
|
-
cascadeLoaderData(routeMatch);
|
|
1021
1042
|
routeMatch.error = undefined;
|
|
1022
1043
|
routeMatch.status = 'success';
|
|
1023
1044
|
routeMatch.updatedAt = Date.now();
|
|
@@ -1077,16 +1098,14 @@ function createRouteMatch(router, route, opts) {
|
|
|
1077
1098
|
return routeMatch;
|
|
1078
1099
|
}
|
|
1079
1100
|
|
|
1080
|
-
function cascadeLoaderData(
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
}
|
|
1101
|
+
function cascadeLoaderData(matches) {
|
|
1102
|
+
matches.forEach((match, index) => {
|
|
1103
|
+
const parent = matches[index - 1];
|
|
1084
1104
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1105
|
+
if (parent) {
|
|
1106
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _rollupPluginBabelHelpers["extends"]({}, parent.loaderData, match.routeLoaderData));
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1090
1109
|
}
|
|
1091
1110
|
|
|
1092
1111
|
function matchPathname(currentPathname, matchLocation) {
|