@tanstack/router-devtools 0.0.1-beta.133 → 0.0.1-beta.135

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.
@@ -74,52 +74,10 @@
74
74
  */
75
75
 
76
76
  function useStore(store, selector = d => d) {
77
- // const isMountedRef = React.useRef(false)
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
-
77
+ const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
120
78
  return slice;
121
79
  }
122
- function shallow$1(objA, objB) {
80
+ function shallow(objA, objB) {
123
81
  if (Object.is(objA, objB)) {
124
82
  return true;
125
83
  }
@@ -157,35 +115,7 @@
157
115
  function trimPath(path) {
158
116
  return trimPathRight(trimPathLeft(path));
159
117
  }
160
- const routerStateContext = /*#__PURE__*/React__namespace.createContext(null);
161
118
  const routerContext = /*#__PURE__*/React__namespace.createContext(null);
162
- function useRouterState(select) {
163
- const state = React__namespace.useContext(routerStateContext);
164
- const next = select?.(state) ?? state;
165
- const valueRef = React__namespace.useRef(next);
166
- if (!shallow(valueRef.current, next)) {
167
- valueRef.current = next;
168
- }
169
- return valueRef.current;
170
- }
171
- function shallow(objA, objB) {
172
- if (Object.is(objA, objB)) {
173
- return true;
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;
188
- }
189
119
 
190
120
  const getItem = key => {
191
121
  try {
@@ -903,14 +833,13 @@
903
833
  } = props;
904
834
  const routerContextValue = React__default["default"].useContext(routerContext);
905
835
  const router = userRouter ?? routerContextValue;
906
- const routerState = useRouterState();
907
836
  invariant(router, 'No router was found for the TanStack Router Devtools. Please place the devtools in the <RouterProvider> component tree or pass the router instance to the devtools manually.');
908
837
  useStore(router.__store);
909
838
  const [showMatches, setShowMatches] = useLocalStorage('tanstackRouterDevtoolsShowMatches', true);
910
839
  const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
911
- const allMatches = React__default["default"].useMemo(() => [...Object.values(routerState.matches)], [routerState.matches]);
840
+ const allMatches = React__default["default"].useMemo(() => [...Object.values(router.state.matches)], [router.state.matches]);
912
841
  const activeMatch = allMatches?.find(d => d.routeId === activeRouteId);
913
- const hasSearch = Object.keys(routerState.location.search || {}).length;
842
+ const hasSearch = Object.keys(router.state.location.search || {}).length;
914
843
  return /*#__PURE__*/React__default["default"].createElement(ThemeProvider, {
915
844
  theme: defaultTheme
916
845
  }, /*#__PURE__*/React__default["default"].createElement(Panel, _extends({
@@ -1078,7 +1007,7 @@
1078
1007
  matches: allMatches,
1079
1008
  activeRouteId: activeRouteId,
1080
1009
  setActiveRouteId: setActiveRouteId
1081
- }) : /*#__PURE__*/React__default["default"].createElement("div", null, routerState.matches.map((match, i) => {
1010
+ }) : /*#__PURE__*/React__default["default"].createElement("div", null, router.state.matches.map((match, i) => {
1082
1011
  return /*#__PURE__*/React__default["default"].createElement("div", {
1083
1012
  key: match.routeId || i,
1084
1013
  role: "button",
@@ -1175,8 +1104,8 @@
1175
1104
  padding: '.5em'
1176
1105
  }
1177
1106
  }, /*#__PURE__*/React__default["default"].createElement(Explorer, {
1178
- value: routerState.location.search || {},
1179
- defaultExpanded: Object.keys(routerState.location.search || {}).reduce((obj, next) => {
1107
+ value: router.state.location.search || {},
1108
+ defaultExpanded: Object.keys(router.state.location.search || {}).reduce((obj, next) => {
1180
1109
  obj[next] = {};
1181
1110
  return obj;
1182
1111
  }, {})