Fix typescript compilation error on public properties
Signed-off-by: Bryan Frimin <bryan@getprobo.com> Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
155bbbd840
commit
fb9bce0282
@@ -8,7 +8,11 @@ import {
|
||||
const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions";
|
||||
|
||||
class ReloadStorage {
|
||||
constructor(public readonly storageKey = DEFAULT_STORAGE_KEY) {}
|
||||
public readonly storageKey: string;
|
||||
|
||||
constructor(storageKey = DEFAULT_STORAGE_KEY) {
|
||||
this.storageKey = storageKey;
|
||||
}
|
||||
|
||||
getMap(): Map<string, number> {
|
||||
const stored = sessionStorage.getItem(this.storageKey);
|
||||
@@ -21,9 +25,9 @@ class ReloadStorage {
|
||||
(value) =>
|
||||
Array.isArray(value) &&
|
||||
typeof value[0] === "string" &&
|
||||
typeof value[1] === "number"
|
||||
typeof value[1] === "number",
|
||||
)
|
||||
: []
|
||||
: [],
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error parsing react-lazy storage:", error);
|
||||
@@ -46,7 +50,7 @@ class ReloadStorage {
|
||||
protected save(stored: Map<string, number>): void {
|
||||
sessionStorage.setItem(
|
||||
this.storageKey,
|
||||
JSON.stringify([...stored.entries()])
|
||||
JSON.stringify([...stored.entries()]),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +89,9 @@ const createConfig = (init: LazyConfigInit = {}): LazyConfig => ({
|
||||
? Math.max(0, init.importRetries)
|
||||
: 0,
|
||||
retryDelay:
|
||||
typeof init.retryDelay === "number" ? Math.max(0, init.retryDelay) : 300,
|
||||
typeof init.retryDelay === "number"
|
||||
? Math.max(0, init.retryDelay)
|
||||
: 300,
|
||||
onImportError: init.onImportError,
|
||||
});
|
||||
|
||||
@@ -95,14 +101,16 @@ export function createLazy<P = {}>(config: LazyConfigInit = {}) {
|
||||
const reloadStorage = new ReloadStorage(forceReload.storageKey);
|
||||
|
||||
function enhancedLazy<T = P>(
|
||||
importFunction: () => Promise<{ default: ComponentType<T> }>
|
||||
importFunction: () => Promise<{ default: ComponentType<T> }>,
|
||||
): LazyExoticComponent<ComponentType<T>> {
|
||||
const functionString = importFunction.toString();
|
||||
|
||||
const importWithRetry = async () => {
|
||||
let retryCount = 0;
|
||||
|
||||
const tryImport = async (): Promise<{ default: ComponentType<T> }> => {
|
||||
const tryImport = async (): Promise<{
|
||||
default: ComponentType<T>;
|
||||
}> => {
|
||||
try {
|
||||
return await importFunction();
|
||||
} catch (error) {
|
||||
@@ -116,7 +124,9 @@ export function createLazy<P = {}>(config: LazyConfigInit = {}) {
|
||||
retryCount++;
|
||||
|
||||
if (retryDelay > 0) {
|
||||
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, retryDelay),
|
||||
);
|
||||
}
|
||||
|
||||
return tryImport();
|
||||
|
||||
Reference in New Issue
Block a user