@tanstack/react-router 0.0.1-beta.53 → 0.0.1-beta.55
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/index.js +48 -73
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +18 -89
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +66 -76
- package/build/types/index.d.ts +5 -17
- package/build/umd/index.development.js +263 -613
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +23 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -5
- package/src/index.tsx +16 -84
- package/build/cjs/useStore.js +0 -64
- package/build/cjs/useStore.js.map +0 -1
- package/src/useStore.ts +0 -70
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.55",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router/",
|
|
@@ -41,12 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/runtime": "^7.16.7",
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"@tanstack/router-core": "0.0.1-beta.53"
|
|
44
|
+
"@tanstack/router": "0.0.1-beta.55",
|
|
45
|
+
"@tanstack/react-store": "0.0.1-beta.55"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@types/use-sync-external-store": "^0.0.3",
|
|
50
48
|
"babel-plugin-transform-async-to-promises": "^0.8.18"
|
|
51
49
|
}
|
|
52
50
|
}
|
package/src/index.tsx
CHANGED
|
@@ -25,15 +25,12 @@ import {
|
|
|
25
25
|
invariant,
|
|
26
26
|
Router,
|
|
27
27
|
Expand,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ActionSubmission,
|
|
31
|
-
} from '@tanstack/router-core'
|
|
32
|
-
import { useStore } from './useStore'
|
|
28
|
+
} from '@tanstack/router'
|
|
29
|
+
import { useStore } from '@tanstack/react-store'
|
|
33
30
|
|
|
34
31
|
//
|
|
35
32
|
|
|
36
|
-
export * from '@tanstack/router
|
|
33
|
+
export * from '@tanstack/router'
|
|
37
34
|
|
|
38
35
|
export { useStore }
|
|
39
36
|
|
|
@@ -114,7 +111,7 @@ export type MakeLinkOptions<
|
|
|
114
111
|
children?: ReactNode | ((state: { isActive: boolean }) => ReactNode)
|
|
115
112
|
}
|
|
116
113
|
|
|
117
|
-
declare module '@tanstack/router
|
|
114
|
+
declare module '@tanstack/router' {
|
|
118
115
|
interface FrameworkGenerics {
|
|
119
116
|
Component: RouteComponent
|
|
120
117
|
ErrorComponent: RouteComponent<{
|
|
@@ -432,32 +429,6 @@ export function useRoute<
|
|
|
432
429
|
return resolvedRoute as any
|
|
433
430
|
}
|
|
434
431
|
|
|
435
|
-
export function useLoaderData<
|
|
436
|
-
TFrom extends keyof RegisteredAllRouteInfo['routeInfoById'] = '/',
|
|
437
|
-
TStrict extends boolean = true,
|
|
438
|
-
TLoaderData = RegisteredAllRouteInfo['routeInfoById'][TFrom]['loaderData'],
|
|
439
|
-
>(opts?: {
|
|
440
|
-
from: TFrom
|
|
441
|
-
strict?: TStrict
|
|
442
|
-
track?: (loaderData: TLoaderData) => any
|
|
443
|
-
}): TStrict extends true ? TLoaderData : TLoaderData | undefined {
|
|
444
|
-
const match = useMatch(opts)
|
|
445
|
-
|
|
446
|
-
invariant(
|
|
447
|
-
match,
|
|
448
|
-
`Could not find ${
|
|
449
|
-
opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'
|
|
450
|
-
}`,
|
|
451
|
-
)
|
|
452
|
-
|
|
453
|
-
useStore(
|
|
454
|
-
(match as any).store,
|
|
455
|
-
(d: any) => opts?.track?.(d.loaderData) ?? d.loaderData,
|
|
456
|
-
)
|
|
457
|
-
|
|
458
|
-
return (match as unknown as RouteMatch).store.state.loaderData as any
|
|
459
|
-
}
|
|
460
|
-
|
|
461
432
|
export function useSearch<
|
|
462
433
|
TFrom extends keyof RegisteredAllRouteInfo['routeInfoById'],
|
|
463
434
|
TStrict extends boolean = true,
|
|
@@ -583,7 +554,7 @@ function SubOutlet({
|
|
|
583
554
|
)
|
|
584
555
|
}
|
|
585
556
|
|
|
586
|
-
if (props.match.store.state.status === '
|
|
557
|
+
if (props.match.store.state.status === 'pending') {
|
|
587
558
|
throw props.match.__loadPromise
|
|
588
559
|
}
|
|
589
560
|
|
|
@@ -673,33 +644,26 @@ function CatchBoundaryInner(props: {
|
|
|
673
644
|
)
|
|
674
645
|
const router = useRouter()
|
|
675
646
|
const errorComponent = props.errorComponent ?? DefaultErrorBoundary
|
|
647
|
+
const prevKeyRef = React.useRef('' as any)
|
|
676
648
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
// prevKey = router.store.state.currentLocation.key
|
|
684
|
-
// setActiveErrorState({} as any)
|
|
685
|
-
// }
|
|
686
|
-
// })
|
|
687
|
-
|
|
688
|
-
// return dispose
|
|
689
|
-
// })
|
|
690
|
-
// }
|
|
649
|
+
React.useEffect(() => {
|
|
650
|
+
if (activeErrorState) {
|
|
651
|
+
if (router.store.state.currentLocation.key !== prevKeyRef.current) {
|
|
652
|
+
setActiveErrorState({} as any)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
691
655
|
|
|
692
|
-
|
|
693
|
-
|
|
656
|
+
prevKeyRef.current = router.store.state.currentLocation.key
|
|
657
|
+
}, [activeErrorState, router.store.state.currentLocation.key])
|
|
694
658
|
|
|
695
659
|
React.useEffect(() => {
|
|
696
660
|
if (props.errorState.error) {
|
|
697
661
|
setActiveErrorState(props.errorState)
|
|
698
662
|
}
|
|
699
|
-
props.reset()
|
|
663
|
+
// props.reset()
|
|
700
664
|
}, [props.errorState.error])
|
|
701
665
|
|
|
702
|
-
if (props.errorState.error) {
|
|
666
|
+
if (props.errorState.error && activeErrorState.error) {
|
|
703
667
|
return React.createElement(errorComponent, activeErrorState)
|
|
704
668
|
}
|
|
705
669
|
|
|
@@ -732,38 +696,6 @@ export function DefaultErrorBoundary({ error }: { error: any }) {
|
|
|
732
696
|
)
|
|
733
697
|
}
|
|
734
698
|
|
|
735
|
-
export function useAction<
|
|
736
|
-
TKey extends string = string,
|
|
737
|
-
TPayload = unknown,
|
|
738
|
-
TResponse = unknown,
|
|
739
|
-
TError = Error,
|
|
740
|
-
>(
|
|
741
|
-
action: Action<TKey, TPayload, TResponse, TError>,
|
|
742
|
-
opts?: {
|
|
743
|
-
track?: (actionStore: ActionStore<TPayload, TResponse, TError>) => any
|
|
744
|
-
},
|
|
745
|
-
): Action & {
|
|
746
|
-
latestSubmission: ActionSubmission<TPayload, TResponse, TError>
|
|
747
|
-
pendingSubmissions: ActionSubmission<TPayload, TResponse, TError>[]
|
|
748
|
-
} {
|
|
749
|
-
useStore(action.store, (d) => opts?.track?.(d) ?? d, true)
|
|
750
|
-
|
|
751
|
-
const [ref] = React.useState({})
|
|
752
|
-
|
|
753
|
-
Object.assign(ref, {
|
|
754
|
-
...action,
|
|
755
|
-
latestSubmission:
|
|
756
|
-
action.store.state.submissions[action.store.state.submissions.length - 1],
|
|
757
|
-
pendingSubmissions: React.useMemo(
|
|
758
|
-
() =>
|
|
759
|
-
action.store.state.submissions.filter((d) => d.status === 'pending'),
|
|
760
|
-
[action.store.state.submissions],
|
|
761
|
-
),
|
|
762
|
-
})
|
|
763
|
-
|
|
764
|
-
return ref as any
|
|
765
|
-
}
|
|
766
|
-
|
|
767
699
|
// TODO: While we migrate away from the history package, these need to be disabled
|
|
768
700
|
// export function usePrompt(message: string, when: boolean | any): void {
|
|
769
701
|
// const router = useRouter()
|
package/build/cjs/useStore.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-router
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
16
|
-
|
|
17
|
-
function useStore(store, selector = d => d, compareShallow) {
|
|
18
|
-
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined);
|
|
19
|
-
return slice;
|
|
20
|
-
}
|
|
21
|
-
function shallow(objA, objB) {
|
|
22
|
-
if (Object.is(objA, objB)) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// if (objA instanceof Map && objB instanceof Map) {
|
|
30
|
-
// if (objA.size !== objB.size) return false
|
|
31
|
-
|
|
32
|
-
// for (const [key, value] of objA) {
|
|
33
|
-
// if (!Object.is(value, objB.get(key))) {
|
|
34
|
-
// return false
|
|
35
|
-
// }
|
|
36
|
-
// }
|
|
37
|
-
// return true
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// if (objA instanceof Set && objB instanceof Set) {
|
|
41
|
-
// if (objA.size !== objB.size) return false
|
|
42
|
-
|
|
43
|
-
// for (const value of objA) {
|
|
44
|
-
// if (!objB.has(value)) {
|
|
45
|
-
// return false
|
|
46
|
-
// }
|
|
47
|
-
// }
|
|
48
|
-
// return true
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
const keysA = Object.keys(objA);
|
|
52
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
56
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
exports.useStore = useStore;
|
|
64
|
-
//# sourceMappingURL=useStore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.js","sources":["../../src/useStore.ts"],"sourcesContent":["import { Store } from '@tanstack/router-core'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport function useStore<TState, TSelected = TState>(\n store: Store<TState>,\n selector: (state: TState) => TSelected = (d) => d as any,\n compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\nfunction shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n // if (objA instanceof Map && objB instanceof Map) {\n // if (objA.size !== objB.size) return false\n\n // for (const [key, value] of objA) {\n // if (!Object.is(value, objB.get(key))) {\n // return false\n // }\n // }\n // return true\n // }\n\n // if (objA instanceof Set && objB instanceof Set) {\n // if (objA.size !== objB.size) return false\n\n // for (const value of objA) {\n // if (!objB.has(value)) {\n // return false\n // }\n // }\n // return true\n // }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n"],"names":["useStore","store","selector","d","compareShallow","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","undefined","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;;;;;;;;;AAGO,SAASA,QAAQ,CACtBC,KAAoB,EACpBC,QAAsC,GAAIC,CAAC,IAAKA,CAAQ,EACxDC,cAAwB,EACxB;EACA,MAAMC,KAAK,GAAGC,6CAAgC,CAC5CL,KAAK,CAACM,SAAS,EACf,MAAMN,KAAK,CAACO,KAAK,EACjB,MAAMP,KAAK,CAACO,KAAK,EACjBN,QAAQ,EACRE,cAAc,GAAGK,OAAO,GAAGC,SAAS,CACrC,CAAA;AAED,EAAA,OAAOL,KAAK,CAAA;AACd,CAAA;AAEA,SAASI,OAAO,CAAIE,IAAO,EAAEC,IAAO,EAAE;EACpC,IAAIC,MAAM,CAACC,EAAE,CAACH,IAAI,EAAEC,IAAI,CAAC,EAAE;AACzB,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;AAEA,EAAA,IACE,OAAOD,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,IACb,OAAOC,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,EACb;AACA,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,EAAA,MAAMG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAACL,IAAI,CAAC,CAAA;AAC/B,EAAA,IAAII,KAAK,CAACE,MAAM,KAAKJ,MAAM,CAACG,IAAI,CAACJ,IAAI,CAAC,CAACK,MAAM,EAAE;AAC7C,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEA,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACE,MAAM,EAAEC,CAAC,EAAE,EAAE;AACrC,IAAA,IACE,CAACL,MAAM,CAACM,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,IAAI,EAAEG,KAAK,CAACG,CAAC,CAAC,CAAW,IAC/D,CAACL,MAAM,CAACC,EAAE,CAACH,IAAI,CAACI,KAAK,CAACG,CAAC,CAAC,CAAY,EAAEN,IAAI,CAACG,KAAK,CAACG,CAAC,CAAC,CAAY,CAAC,EAChE;AACA,MAAA,OAAO,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,OAAO,IAAI,CAAA;AACb;;;;"}
|
package/src/useStore.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Store } from '@tanstack/router-core'
|
|
2
|
-
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
|
|
3
|
-
|
|
4
|
-
export function useStore<TState, TSelected = TState>(
|
|
5
|
-
store: Store<TState>,
|
|
6
|
-
selector: (state: TState) => TSelected = (d) => d as any,
|
|
7
|
-
compareShallow?: boolean,
|
|
8
|
-
) {
|
|
9
|
-
const slice = useSyncExternalStoreWithSelector(
|
|
10
|
-
store.subscribe,
|
|
11
|
-
() => store.state,
|
|
12
|
-
() => store.state,
|
|
13
|
-
selector,
|
|
14
|
-
compareShallow ? shallow : undefined,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
return slice
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function shallow<T>(objA: T, objB: T) {
|
|
21
|
-
if (Object.is(objA, objB)) {
|
|
22
|
-
return true
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
typeof objA !== 'object' ||
|
|
27
|
-
objA === null ||
|
|
28
|
-
typeof objB !== 'object' ||
|
|
29
|
-
objB === null
|
|
30
|
-
) {
|
|
31
|
-
return false
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// if (objA instanceof Map && objB instanceof Map) {
|
|
35
|
-
// if (objA.size !== objB.size) return false
|
|
36
|
-
|
|
37
|
-
// for (const [key, value] of objA) {
|
|
38
|
-
// if (!Object.is(value, objB.get(key))) {
|
|
39
|
-
// return false
|
|
40
|
-
// }
|
|
41
|
-
// }
|
|
42
|
-
// return true
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
// if (objA instanceof Set && objB instanceof Set) {
|
|
46
|
-
// if (objA.size !== objB.size) return false
|
|
47
|
-
|
|
48
|
-
// for (const value of objA) {
|
|
49
|
-
// if (!objB.has(value)) {
|
|
50
|
-
// return false
|
|
51
|
-
// }
|
|
52
|
-
// }
|
|
53
|
-
// return true
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
const keysA = Object.keys(objA)
|
|
57
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
58
|
-
return false
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
62
|
-
if (
|
|
63
|
-
!Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||
|
|
64
|
-
!Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])
|
|
65
|
-
) {
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return true
|
|
70
|
-
}
|