@kwiz/fluentui 1.0.171 → 1.0.173
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { iLoadingProps } from "../controls/loading";
|
|
2
2
|
import { iPleaseWaitProps } from "../controls/please-wait";
|
|
3
|
-
type queueType = "required" | "optional";
|
|
3
|
+
type queueType = "required" | "optional" | "idle";
|
|
4
4
|
type isLoadingType = {
|
|
5
5
|
type: queueType;
|
|
6
6
|
label?: string;
|
|
@@ -13,13 +13,13 @@ export interface iUseReloadTracker<Scope extends string = "global"> {
|
|
|
13
13
|
/** call to reload scope+global, or send global to reload all scopes */
|
|
14
14
|
reload: (scope?: Scope) => void;
|
|
15
15
|
/** state: is there pending promises in the queue */
|
|
16
|
-
isLoading: isLoadingType
|
|
16
|
+
isLoading: isLoadingType;
|
|
17
17
|
/** add a loading promise to the queue */
|
|
18
18
|
queue: <Result>(promise: () => Promise<Result>, info: {
|
|
19
19
|
label: string;
|
|
20
20
|
type?: queueType;
|
|
21
21
|
/** will use promiseOnce if provided, along with the reload key */
|
|
22
|
-
cacheKey
|
|
22
|
+
cacheKey?: string;
|
|
23
23
|
/** switch reloadKey scope for cacheKey. Global will update on any reload. You want to set this if you have a dependency on reloadKey.[scope] that is not global */
|
|
24
24
|
cacheScope?: Scope;
|
|
25
25
|
}) => Promise<Result>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { CommonLogger, debounce, firstIndexOf, firstOrNull, isNotEmptyString, isNullOrEmptyString, isNumber, jsonClone, promiseOnce } from "@kwiz/common";
|
|
12
|
-
import { isValidElement, useCallback, useMemo } from "react";
|
|
12
|
+
import { isValidElement, useCallback, useMemo, useRef } from "react";
|
|
13
13
|
import { Loading } from "../controls/loading";
|
|
14
14
|
import { PleaseWait } from "../controls/please-wait";
|
|
15
15
|
import { useStateEX } from "./hooks";
|
|
@@ -17,8 +17,8 @@ const logger = new CommonLogger("useReloadTracker");
|
|
|
17
17
|
/** a simple reload marker, can be used as a dependency, and called as a function */
|
|
18
18
|
export function useReloadTracker(props) {
|
|
19
19
|
const [reloadKey, setReload, reloadKeyRef] = useStateEX({ global: 1 });
|
|
20
|
-
const promises = [];
|
|
21
|
-
let counter = 1;
|
|
20
|
+
const promises = useRef([]);
|
|
21
|
+
let counter = useRef(1);
|
|
22
22
|
const reload = useCallback(debounce((scope) => {
|
|
23
23
|
const rk = jsonClone(reloadKey);
|
|
24
24
|
if (scope === "global" || isNullOrEmptyString(scope)) {
|
|
@@ -36,17 +36,16 @@ export function useReloadTracker(props) {
|
|
|
36
36
|
}
|
|
37
37
|
setReload(rk);
|
|
38
38
|
}, 100), [reloadKey]);
|
|
39
|
-
const [isLoading, setLoading, isLoadingRef] = useStateEX(
|
|
39
|
+
const [isLoading, setLoading, isLoadingRef] = useStateEX({ type: "idle" }, { skipUpdateIfSame: true });
|
|
40
40
|
//this does not have dependencies, never changes, so unsafe to use state. use stateRef objects.
|
|
41
41
|
const queue = useCallback((promise, info) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
var _a;
|
|
43
42
|
const type = (info === null || info === void 0 ? void 0 : info.type) || "optional";
|
|
44
|
-
if (
|
|
43
|
+
if (isLoadingRef.current.type !== "required") //if its required - do not update this back to optional
|
|
45
44
|
setLoading({ type, label: info.label });
|
|
46
|
-
const myId = counter++;
|
|
47
|
-
promises.push({ id: myId, type, label: info === null || info === void 0 ? void 0 : info.label });
|
|
45
|
+
const myId = counter.current++;
|
|
46
|
+
promises.current.push({ id: myId, type, label: info === null || info === void 0 ? void 0 : info.label });
|
|
48
47
|
try {
|
|
49
|
-
return (isNotEmptyString(info.cacheKey)
|
|
48
|
+
return yield (isNotEmptyString(info.cacheKey)
|
|
50
49
|
? (() => {
|
|
51
50
|
const cache_reloadKey = isNotEmptyString(info.cacheScope) ? `${info.cacheScope}:${reloadKeyRef.current[info.cacheScope] || 0}` : `global:${reloadKeyRef.current.global}`;
|
|
52
51
|
const promiseOnceCacheKey = `${cache_reloadKey}|${info.cacheKey}`;
|
|
@@ -57,26 +56,28 @@ export function useReloadTracker(props) {
|
|
|
57
56
|
}
|
|
58
57
|
finally {
|
|
59
58
|
//remove this promise
|
|
60
|
-
const myIndex = firstIndexOf(promises, p => p.id === myId);
|
|
61
|
-
promises.splice(myIndex, 1);
|
|
59
|
+
const myIndex = firstIndexOf(promises.current, p => p.id === myId);
|
|
60
|
+
promises.current.splice(myIndex, 1);
|
|
62
61
|
//if no more promises - set loading to false
|
|
63
|
-
if (promises.length === 0)
|
|
64
|
-
setLoading(
|
|
62
|
+
if (promises.current.length === 0)
|
|
63
|
+
setLoading({ type: "idle" });
|
|
65
64
|
//else, if it is state required and no more required promiese - drop it to optional
|
|
66
65
|
else {
|
|
67
66
|
//drop the label/type to the next promise in queue, prioritize required ones.
|
|
68
|
-
const nextPromise = firstOrNull(promises, p_1 => p_1.type === "required") || promises[0];
|
|
67
|
+
const nextPromise = firstOrNull(promises.current, p_1 => p_1.type === "required") || promises.current[0];
|
|
69
68
|
setLoading({ type: nextPromise.type, label: nextPromise.label });
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
}), []);
|
|
73
|
-
const reloadElement = useMemo(() =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
const reloadElement = useMemo(() => {
|
|
73
|
+
return (isLoading === null || isLoading === void 0 ? void 0 : isLoading.type) === "required"
|
|
74
|
+
? isValidElement(props === null || props === void 0 ? void 0 : props.requiredElement) ? props.requiredElement
|
|
75
|
+
: _jsx(Loading, Object.assign({ fullsize: true, label: isLoading.label }, props === null || props === void 0 ? void 0 : props.requiredElement))
|
|
76
|
+
: (isLoading === null || isLoading === void 0 ? void 0 : isLoading.type) === "optional"
|
|
77
|
+
? isValidElement(props === null || props === void 0 ? void 0 : props.optionalElement) ? props.optionalElement
|
|
78
|
+
: _jsx(PleaseWait, Object.assign({ label: isLoading.label }, props === null || props === void 0 ? void 0 : props.optionalElement))
|
|
79
|
+
: undefined;
|
|
80
|
+
}, [isLoading.type, isLoading.label]);
|
|
80
81
|
return {
|
|
81
82
|
reloadKey, reload, isLoading, queue, reloadElement
|
|
82
83
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reload-tracker.js","sourceRoot":"","sources":["../../src/helpers/use-reload-tracker.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1J,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-reload-tracker.js","sourceRoot":"","sources":["../../src/helpers/use-reload-tracker.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1J,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAiB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAoB,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC;AA0BpD,oFAAoF;AACpF,MAAM,UAAU,gBAAgB,CAAkC,K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