Use custom lazy for loading components

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Jonathan
2025-06-11 18:39:11 +02:00
committed by Sacha Al Himdani
parent 1ba61f691e
commit e1b63b59a6
13 changed files with 47 additions and 43 deletions

View File

@@ -5,9 +5,9 @@ import {
type FC,
} from "react";
export const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions";
const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions";
export class ReloadStorage {
class ReloadStorage {
constructor(public readonly storageKey = DEFAULT_STORAGE_KEY) {}
getMap(): Map<string, number> {
@@ -51,24 +51,24 @@ export class ReloadStorage {
}
}
export interface ForceReloadConfig {
type ForceReloadConfig = {
maxRetries: number;
storageKey?: string;
}
};
export interface LazyConfigInit {
type LazyConfigInit = {
forceReload?: false | Partial<ForceReloadConfig>;
importRetries?: number;
retryDelay?: number;
onImportError?: (error: unknown) => void;
}
};
export interface LazyConfig {
type LazyConfig = {
forceReload: ForceReloadConfig;
importRetries: number;
retryDelay: number;
onImportError?: (error: unknown) => void;
}
};
const createConfig = (init: LazyConfigInit = {}): LazyConfig => ({
forceReload: {
@@ -77,8 +77,8 @@ const createConfig = (init: LazyConfigInit = {}): LazyConfig => ({
...(typeof init.forceReload === "object"
? init.forceReload
: init.forceReload === false
? { maxRetries: 0 }
: {}),
? { maxRetries: 0 }
: {}),
},
importRetries:
typeof init.importRetries === "number"