@tanstack/router-devtools 0.0.1-beta.133 → 0.0.1-beta.134
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.
|
@@ -62,6 +62,24 @@
|
|
|
62
62
|
throw new Error(value);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
function warning(condition, message) {
|
|
66
|
+
{
|
|
67
|
+
if (condition) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var text = "Warning: " + message;
|
|
72
|
+
|
|
73
|
+
if (typeof console !== 'undefined') {
|
|
74
|
+
console.warn(text);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
throw Error(text);
|
|
79
|
+
} catch (x) {}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
/**
|
|
66
84
|
* @tanstack/react-store/src/index.tsx
|
|
67
85
|
*
|
|
@@ -74,52 +92,10 @@
|
|
|
74
92
|
*/
|
|
75
93
|
|
|
76
94
|
function useStore(store, selector = d => d) {
|
|
77
|
-
|
|
78
|
-
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({
|
|
79
|
-
// ref: selector(store.state),
|
|
80
|
-
// }))
|
|
81
|
-
|
|
82
|
-
// if (!shallow(selector(store.state), state.ref)) {
|
|
83
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
84
|
-
// }
|
|
85
|
-
|
|
86
|
-
// useLayoutEffect(() => {
|
|
87
|
-
// console.log('effect')
|
|
88
|
-
|
|
89
|
-
// const cb = () => {
|
|
90
|
-
// const next = selector(store.state)
|
|
91
|
-
// console.log('onsub')
|
|
92
|
-
// if (!shallow(next, state.ref)) {
|
|
93
|
-
// console.log('set')
|
|
94
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
95
|
-
// }
|
|
96
|
-
// }
|
|
97
|
-
|
|
98
|
-
// return store.subscribe(cb)
|
|
99
|
-
// }, [])
|
|
100
|
-
|
|
101
|
-
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow$1);
|
|
102
|
-
|
|
103
|
-
// if (!isMountedRef.current) {
|
|
104
|
-
// state.ref = slice
|
|
105
|
-
// }
|
|
106
|
-
|
|
107
|
-
// if (!shallow(slice, state.ref)) {
|
|
108
|
-
// setState({ ref: slice })
|
|
109
|
-
// }
|
|
110
|
-
|
|
111
|
-
// React.useEffect(() => {
|
|
112
|
-
// isMountedRef.current = true
|
|
113
|
-
// return () => {
|
|
114
|
-
// isMountedRef.current = false
|
|
115
|
-
// }
|
|
116
|
-
// }, [])
|
|
117
|
-
|
|
118
|
-
// return state.ref
|
|
119
|
-
|
|
95
|
+
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
|
|
120
96
|
return slice;
|
|
121
97
|
}
|
|
122
|
-
function shallow
|
|
98
|
+
function shallow(objA, objB) {
|
|
123
99
|
if (Object.is(objA, objB)) {
|
|
124
100
|
return true;
|
|
125
101
|
}
|
|
@@ -157,34 +133,15 @@
|
|
|
157
133
|
function trimPath(path) {
|
|
158
134
|
return trimPathRight(trimPathLeft(path));
|
|
159
135
|
}
|
|
160
|
-
const routerStateContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
161
136
|
const routerContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
162
|
-
function useRouterState(
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
const valueRef = React__namespace.useRef(next);
|
|
166
|
-
if (!shallow(valueRef.current, next)) {
|
|
167
|
-
valueRef.current = next;
|
|
168
|
-
}
|
|
169
|
-
return valueRef.current;
|
|
137
|
+
function useRouterState(opts) {
|
|
138
|
+
const router = useRouter();
|
|
139
|
+
return useStore(router.__store, opts?.select);
|
|
170
140
|
}
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
const keysA = Object.keys(objA);
|
|
179
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
183
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return true;
|
|
141
|
+
function useRouter() {
|
|
142
|
+
const value = React__namespace.useContext(routerContext);
|
|
143
|
+
warning(value, 'useRouter must be used inside a <Router> component!');
|
|
144
|
+
return value;
|
|
188
145
|
}
|
|
189
146
|
|
|
190
147
|
const getItem = key => {
|