akanjs 3.1.0-rc.12 → 3.1.0-rc.13
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/package.json +1 -1
- package/store/action.ts +10 -4
- package/types/store/action.d.ts +2 -0
- package/ui/Load/Units.tsx +4 -2
package/package.json
CHANGED
package/store/action.ts
CHANGED
|
@@ -136,7 +136,7 @@ type BaseAction<
|
|
|
136
136
|
) => Promise<void>;
|
|
137
137
|
} & { [K in `set${_CapitalizedRefName}`]: (...models: (Full | Light)[]) => void } & {
|
|
138
138
|
[K in `reset${_CapitalizedRefName}`]: (model?: Full) => void;
|
|
139
|
-
};
|
|
139
|
+
} & { [K in `invalidate${_CapitalizedRefName}`]: () => void };
|
|
140
140
|
|
|
141
141
|
export type SliceAction<
|
|
142
142
|
RefName extends string,
|
|
@@ -543,6 +543,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
543
543
|
viewModel: `view${className}`,
|
|
544
544
|
setModel: `set${className}`,
|
|
545
545
|
resetModel: `reset${className}`,
|
|
546
|
+
invalidateModel: `invalidate${className}`,
|
|
546
547
|
loadModelDraft: `load${className}FormDraft`,
|
|
547
548
|
restoreModelDraft: `restore${className}FormDraft`,
|
|
548
549
|
discardModelDraft: `discard${className}FormDraft`,
|
|
@@ -905,6 +906,9 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
905
906
|
});
|
|
906
907
|
return model ?? null;
|
|
907
908
|
},
|
|
909
|
+
[names.invalidateModel]: function (this: SetGet) {
|
|
910
|
+
this.set(staleAtOfSlices());
|
|
911
|
+
},
|
|
908
912
|
|
|
909
913
|
[names.loadModelDraft]: async function (this: SetGet, draftScope?: string) {
|
|
910
914
|
const currentState = this.get() as { [key: string]: any };
|
|
@@ -1033,6 +1037,8 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
1033
1037
|
isQueryEqual(sort as unknown as object, sortOfModel as unknown as object)
|
|
1034
1038
|
)
|
|
1035
1039
|
return;
|
|
1040
|
+
|
|
1041
|
+
const requestedAt = new Date();
|
|
1036
1042
|
await loadList(
|
|
1037
1043
|
this,
|
|
1038
1044
|
() =>
|
|
@@ -1049,7 +1055,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
1049
1055
|
[namesOfSlice.modelList]: modelList,
|
|
1050
1056
|
[namesOfSlice.modelInsight]: modelInsight,
|
|
1051
1057
|
[namesOfSlice.modelInitList]: modelList,
|
|
1052
|
-
[namesOfSlice.modelInitAt]:
|
|
1058
|
+
[namesOfSlice.modelInitAt]: requestedAt,
|
|
1053
1059
|
...lastPageFrom(modelInsight.count, limit),
|
|
1054
1060
|
...hasMoreFrom(modelDataList, fetchLimit),
|
|
1055
1061
|
[namesOfSlice.limitOfModel]: limit,
|
|
@@ -1209,10 +1215,10 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
1209
1215
|
|
|
1210
1216
|
[namesOfSlice.applyLiveModel]: function (this: SetGet, event: LiveEventPayload) {
|
|
1211
1217
|
const currentState = this.get() as { [key: string]: any };
|
|
1212
|
-
if (currentState[namesOfSlice.modelListLoading] as boolean) return;
|
|
1213
1218
|
const modelList = currentState[namesOfSlice.modelList] as DataList<Light>;
|
|
1214
1219
|
const staleAt = { [namesOfSlice.modelStaleAt]: new Date() };
|
|
1215
|
-
|
|
1220
|
+
|
|
1221
|
+
if (event.op === "invalidate" || (currentState[namesOfSlice.modelListLoading] as boolean)) {
|
|
1216
1222
|
this.set(staleAt);
|
|
1217
1223
|
return;
|
|
1218
1224
|
}
|
package/types/store/action.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ type BaseAction<RefName extends string, Input, Full extends {
|
|
|
81
81
|
[K in `set${_CapitalizedRefName}`]: (...models: (Full | Light)[]) => void;
|
|
82
82
|
} & {
|
|
83
83
|
[K in `reset${_CapitalizedRefName}`]: (model?: Full) => void;
|
|
84
|
+
} & {
|
|
85
|
+
[K in `invalidate${_CapitalizedRefName}`]: () => void;
|
|
84
86
|
};
|
|
85
87
|
export type SliceAction<RefName extends string, Suffix extends string, Input, Light, QueryArgs extends any[], Filter extends FilterInstance, _CapitalizedRefName extends string = Capitalize<RefName>, _CapitalizedSuffix extends string = Capitalize<Suffix>, _Sort = ExtractSort<Filter>, _FetchInitFormWithFetchPolicy = FetchInitForm<Input, Filter> & FetchPolicy> = {
|
|
86
88
|
[KDefaultOf in `init${_CapitalizedRefName}${_CapitalizedSuffix}`]: (...args: [...args: QueryArgs, initForm?: _FetchInitFormWithFetchPolicy]) => Promise<void>;
|
package/ui/Load/Units.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { DataList } from "akanjs/base";
|
|
3
|
-
import { cn, router } from "akanjs/client";
|
|
3
|
+
import { cn, isRscNavigationFromCache, router } from "akanjs/client";
|
|
4
4
|
import { type DynamicRecord, isQueryEqual, lowerlize } from "akanjs/common";
|
|
5
5
|
import type { BaseInsight } from "akanjs/constant";
|
|
6
6
|
import { ConstantRegistry, labelOf, withSharedInstances } from "akanjs/constant";
|
|
@@ -142,9 +142,11 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
142
142
|
}, [initSignature, queryArgsSignature]);
|
|
143
143
|
|
|
144
144
|
useEffect(() => {
|
|
145
|
+
|
|
146
|
+
const seededFromReplay = !loaded && isRscNavigationFromCache();
|
|
145
147
|
const modelStaleAt = storeGet<Date>()[namesOfSlice.modelStaleAt];
|
|
146
148
|
const staleThreshold = Math.max(modelStaleAt.getTime(), staleTime === undefined ? 0 : Date.now() - staleTime);
|
|
147
|
-
if (storeGet<Date>()[namesOfSlice.modelInitAt].getTime() >= staleThreshold) return;
|
|
149
|
+
if (!seededFromReplay && storeGet<Date>()[namesOfSlice.modelInitAt].getTime() >= staleThreshold) return;
|
|
148
150
|
if (storeGet<boolean>()[namesOfSlice.modelListLoading]) return;
|
|
149
151
|
void storeDo[namesOfSlice.refreshModel]({ invalidate: true });
|
|
150
152
|
}, [initSignature]);
|