akanjs 3.0.0-alpha.87 → 3.0.0-alpha.88

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.0.0-alpha.87",
3
+ "version": "3.0.0-alpha.88",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/store/action.ts CHANGED
@@ -516,12 +516,11 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
516
516
  queryArgsOfModel: `queryArgsOf${className}`,
517
517
  sortOfModel: `sortOf${className}`,
518
518
  };
519
- const staleAtOfOtherSlices = (createdSliceName: string) => {
519
+
520
+ const staleAtOfSlices = () => {
520
521
  const staleAt = new Date();
521
522
  return Object.fromEntries(
522
- slices
523
- .filter(({ sliceName }) => sliceName !== createdSliceName)
524
- .map(({ sliceName }) => [sliceName.replace(names.model, names.modelStaleAt), staleAt]),
523
+ slices.map(({ sliceName }) => [sliceName.replace(names.model, names.modelStaleAt), staleAt]),
525
524
  );
526
525
  };
527
526
  const baseAction = {
@@ -562,7 +561,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
562
561
  [namesOfSlice.modelInsight]: newModelInsight,
563
562
  [names.modelViewAt]: new Date(),
564
563
  [names.modelModal]: modal ?? null,
565
- ...staleAtOfOtherSlices(sliceName),
564
+ ...staleAtOfSlices(),
566
565
  ...(typeof path === "string" && path ? { [path]: model } : {}),
567
566
  });
568
567
  await onSuccess?.(model);
@@ -593,6 +592,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
593
592
  : {}),
594
593
  [names.modelForm]: immerify(modelRef, defaultModel),
595
594
  [names.modelModal]: modal ?? null,
595
+ ...staleAtOfSlices(),
596
596
  ...(typeof path === "string" && path ? { [path]: updatedModel } : {}),
597
597
  });
598
598
  const updatedLightModel = new cnst.light().set(updatedModel) as unknown as Light;
@@ -645,7 +645,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
645
645
  [namesOfSlice.modelInsight]: newModelInsight,
646
646
  [names.modelViewAt]: new Date(),
647
647
  [names.modelModal]: modal ?? null,
648
- ...staleAtOfOtherSlices(sliceName),
648
+ ...staleAtOfSlices(),
649
649
  ...(typeof path === "string" && path ? { [path]: model } : {}),
650
650
  });
651
651
  await onSuccess?.(model);
@@ -669,6 +669,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
669
669
  ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: new Date() }
670
670
  : {}),
671
671
  [names.modelModal]: modal ?? null,
672
+ ...staleAtOfSlices(),
672
673
  ...(typeof path === "string" && path ? { [path]: updatedModel } : {}),
673
674
  });
674
675
  const updatedLightModel = new cnst.light().set(updatedModel) as unknown as Light;
@@ -729,6 +730,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
729
730
  });
730
731
  }
731
732
  });
733
+ this.set(staleAtOfSlices());
732
734
  },
733
735
  [names.checkModelSubmitable]: function (this: SetGet, disabled?: boolean) {
734
736
  const currentState = this.get() as { [key: string]: any };
@@ -806,6 +808,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
806
808
  this.set({
807
809
  [names.model]: id === model?.id ? updatedModel : model,
808
810
  [names.modelLoading]: false,
811
+ ...staleAtOfSlices(),
809
812
  });
810
813
  const updatedLightModel = new cnst.light().set(updatedModel) as unknown as Light;
811
814
  slices.forEach(({ sliceName }) => {
@@ -863,6 +866,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
863
866
  });
864
867
  this.set({ [namesOfSlice.modelList]: modelList.save() });
865
868
  });
869
+ this.set(staleAtOfSlices());
866
870
  },
867
871
  [names.resetModel]: function (this: SetGet, model?: Full) {
868
872
  const currentState = this.get() as { [key: string]: any };
package/ui/Load/Units.tsx CHANGED
@@ -345,7 +345,7 @@ interface MoreWrapperProps {
345
345
  moreProps: MoreProps;
346
346
  }
347
347
  const MoreWrapper = ({ children, pagination, moreProps }: MoreWrapperProps) => {
348
- return pagination ? <More {...moreProps}>{children}</More> : <>{children}</>;
348
+ return pagination ? <More {...moreProps}>{children}</More> : children;
349
349
  };
350
350
 
351
351
  interface ContainerWrapperProps {
package/ui/Load/View.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { cn } from "akanjs/client";
3
+ import { capitalize } from "akanjs/common";
3
4
  import { ConstantRegistry, labelOf } from "akanjs/constant";
4
5
  import type { ClientView, ServerView } from "akanjs/fetch";
5
6
  import { st } from "akanjs/store";
@@ -40,6 +41,7 @@ function Render<T extends string, Full extends { id: string }>({
40
41
  }: RenderProps<T, Full>) {
41
42
  const loadedId = useRef<string | null>(null);
42
43
  const storeUse = st.use as { [key: string]: () => unknown };
44
+ const storeDo = st.do as unknown as { [key: string]: (...args: any[]) => Promise<void> };
43
45
  const storeGet = st.get as unknown as <T>() => { [key: string]: T };
44
46
  const { refName } = view;
45
47
  const model = storeUse[refName]() as Full | null;
@@ -72,6 +74,14 @@ function Render<T extends string, Full extends { id: string }>({
72
74
  loadedId.current = modelObj.id;
73
75
  }, [modelViewAt, modelObj.id]);
74
76
 
77
+ useEffect(() => {
78
+
79
+ const modelStaleAt = storeGet<Date | undefined>()[`${refName}StaleAt`];
80
+ if (!modelStaleAt || storeGet<Date>()[`${refName}ViewAt`].getTime() >= modelStaleAt.getTime()) return;
81
+ if (storeGet<string | boolean>()[`${refName}Loading`]) return;
82
+ void storeDo[`view${capitalize(refName)}`](modelObj.id);
83
+ }, [modelViewAt, modelObj.id]);
84
+
75
85
  const renderModel = loadedId.current === modelObj.id ? model : modelInit;
76
86
  const scopePath = useScreenScope({
77
87
  id: `${refName}-view`,