clear-react-router 2.0.7 → 2.0.8
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/dist/cell.d.ts +6 -0
- package/dist/index.js +22 -6
- package/dist/types.d.ts +2 -0
- package/dist/utils/commitState.d.ts +1 -1
- package/package.json +1 -1
package/dist/cell.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -30,13 +30,14 @@ var useGlobalState = ({ subscribe, getState, setState }) => {
|
|
|
30
30
|
};
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region utils/commitState.ts
|
|
33
|
-
var createCommitState = ({ routeItemDataState, pendingState, isOptimisticLoading }) => (nextLocation, routeItem) => {
|
|
33
|
+
var createCommitState = ({ routeItemDataState, pendingState, isOptimisticLoading, loaderStateRef, loaderState }) => (nextLocation, routeItem) => {
|
|
34
34
|
routeItemDataState.setState({
|
|
35
35
|
routeItem,
|
|
36
36
|
location: nextLocation
|
|
37
37
|
});
|
|
38
38
|
pendingState.setState(void 0);
|
|
39
39
|
isOptimisticLoading.setState(false);
|
|
40
|
+
loaderState.setState(loaderStateRef.value);
|
|
40
41
|
const fullPath = nextLocation.search ? `${nextLocation.pathname}${nextLocation.search}` : nextLocation.pathname;
|
|
41
42
|
if (fullPath === window.location.pathname + window.location.search) return;
|
|
42
43
|
history.pushState(null, "", fullPath);
|
|
@@ -226,7 +227,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
226
227
|
let navigationSeq = 0;
|
|
227
228
|
let interval = 0;
|
|
228
229
|
let abortController = null;
|
|
229
|
-
const { loaderState, scrollMapState, pendingState, contextState, loaderMap, routeItemDataState, isOptimisticLoading } = routerState;
|
|
230
|
+
const { loaderState, loaderStateRef, scrollMapState, pendingState, contextState, loaderMap, routeItemDataState, isOptimisticLoading } = routerState;
|
|
230
231
|
const navigationExecutor = createCommitState(routerState);
|
|
231
232
|
const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
|
|
232
233
|
const createSignal = () => {
|
|
@@ -240,7 +241,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
240
241
|
setContext: contextState.setState
|
|
241
242
|
});
|
|
242
243
|
const routeResolve = (location) => {
|
|
243
|
-
|
|
244
|
+
loaderStateRef.set(emptyLoaderState);
|
|
244
245
|
const nextItem = findRoute(location.pathname, true);
|
|
245
246
|
return {
|
|
246
247
|
nextItem,
|
|
@@ -257,12 +258,12 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
257
258
|
redirect,
|
|
258
259
|
params
|
|
259
260
|
});
|
|
260
|
-
|
|
261
|
+
loaderStateRef.set((prev) => ({
|
|
261
262
|
...prev,
|
|
262
263
|
beforeLoadError: null
|
|
263
264
|
}));
|
|
264
265
|
} catch (error) {
|
|
265
|
-
|
|
266
|
+
loaderStateRef.set((prev) => ({
|
|
266
267
|
...prev,
|
|
267
268
|
beforeLoadError: error
|
|
268
269
|
}));
|
|
@@ -320,7 +321,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
320
321
|
search: nextLocation.search,
|
|
321
322
|
signal
|
|
322
323
|
}), getLoaderDurationPromise(routeItem, nextLocation)]);
|
|
323
|
-
if (result)
|
|
324
|
+
if (result) loaderStateRef.set((prev) => ({
|
|
324
325
|
...prev,
|
|
325
326
|
...result
|
|
326
327
|
}));
|
|
@@ -535,6 +536,20 @@ var createRevalidateCache = (routerState) => {
|
|
|
535
536
|
return revalidateCache;
|
|
536
537
|
};
|
|
537
538
|
//#endregion
|
|
539
|
+
//#region cell.ts
|
|
540
|
+
var Cell = class {
|
|
541
|
+
constructor(_value) {
|
|
542
|
+
_defineProperty(this, "_value", void 0);
|
|
543
|
+
this._value = _value;
|
|
544
|
+
}
|
|
545
|
+
get value() {
|
|
546
|
+
return this._value;
|
|
547
|
+
}
|
|
548
|
+
set(action) {
|
|
549
|
+
this._value = typeof action === "function" ? action(this._value) : action;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
//#endregion
|
|
538
553
|
//#region utils/createRouterInstance.ts
|
|
539
554
|
var createRouterInstance = () => {
|
|
540
555
|
const routerState = {
|
|
@@ -551,6 +566,7 @@ var createRouterInstance = () => {
|
|
|
551
566
|
}),
|
|
552
567
|
isOptimisticLoading: create(false),
|
|
553
568
|
loaderState: create(emptyLoaderState),
|
|
569
|
+
loaderStateRef: new Cell(emptyLoaderState),
|
|
554
570
|
loaderMap: /* @__PURE__ */ new Map(),
|
|
555
571
|
loadingPromises: /* @__PURE__ */ new Map()
|
|
556
572
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentType, type CSSProperties, Dispatch, MouseEvent, ReactElement, ReactNode, Ref, SetStateAction } from 'react';
|
|
2
2
|
import { Store, useGlobalState } from './create';
|
|
3
|
+
import { Cell } from './cell';
|
|
3
4
|
export declare const LAZY_MARKER: unique symbol;
|
|
4
5
|
export type LazyComponent = {
|
|
5
6
|
readonly [LAZY_MARKER]: true;
|
|
@@ -125,6 +126,7 @@ export type RouterState = {
|
|
|
125
126
|
}>;
|
|
126
127
|
isOptimisticLoading: Store<boolean>;
|
|
127
128
|
loaderState: Store<LoaderState>;
|
|
129
|
+
loaderStateRef: Cell<LoaderState>;
|
|
128
130
|
loaderMap: Map<string, LoaderStateItem>;
|
|
129
131
|
loadingPromises: Map<string, LoadingPromise>;
|
|
130
132
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Location, RouteItem, RouterState } from '../types';
|
|
2
|
-
export declare const createCommitState: ({ routeItemDataState, pendingState, isOptimisticLoading }: RouterState) => (nextLocation: Location, routeItem: RouteItem | undefined) => void;
|
|
2
|
+
export declare const createCommitState: ({ routeItemDataState, pendingState, isOptimisticLoading, loaderStateRef, loaderState }: RouterState) => (nextLocation: Location, routeItem: RouteItem | undefined) => void;
|