react-simple-loadable 2.3.1 → 2.3.3
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/loadable.d.ts +11 -3
- package/loadable.d.ts.map +1 -1
- package/loadable.js +25 -16
- package/package.json +2 -2
package/loadable.d.ts
CHANGED
|
@@ -8,17 +8,25 @@ export interface LoaderComponentProps {
|
|
|
8
8
|
error?: any;
|
|
9
9
|
isLoading?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export type
|
|
11
|
+
export type LoadingComponent = ComponentType<LoaderComponentProps>;
|
|
12
12
|
export interface LoadableConfig {
|
|
13
13
|
throwOnError?: boolean;
|
|
14
|
-
|
|
14
|
+
loading?: LoadingComponent | ComponentType<Record<string, any>>;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use {loading}
|
|
17
|
+
*/
|
|
18
|
+
loader?: LoadingComponent | ComponentType<Record<string, any>>;
|
|
15
19
|
/**
|
|
16
20
|
* Component which renders with the lazy component
|
|
17
21
|
*/
|
|
18
22
|
extra?: ComponentType<any>;
|
|
19
23
|
}
|
|
24
|
+
export interface LoadableConfigWithLoad<P = any> extends LoadableConfig {
|
|
25
|
+
load: LoadComponentFn<P>;
|
|
26
|
+
}
|
|
20
27
|
type LoadableComponent$<P> = LoadableComponent<P>;
|
|
21
28
|
export declare const loadableDefaultConfig: Partial<LoadableConfig>;
|
|
22
|
-
export declare function loadable<P = any>(
|
|
29
|
+
export declare function loadable<P = any>(config: LoadableConfigWithLoad<P>): LoadableComponent$<P>;
|
|
30
|
+
export declare function loadable<P = any>(load: LoadComponentFn<P>, loadingOrConfig?: null | undefined | LoadableConfig['loading'] | LoadableConfig): LoadableComponent$<P>;
|
|
23
31
|
export {};
|
|
24
32
|
//# sourceMappingURL=loadable.d.ts.map
|
package/loadable.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadable.d.ts","sourceRoot":"","sources":["../src/loadable.tsx"],"names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EnE,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAChE;;OAEG;IACH,MAAM,CAAC,EAAE,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/D;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc;IACrE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CAC1B;AAgID,KAAK,kBAAkB,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAElD,eAAO,MAAM,qBAAqB,EAAE,OAAO,CAAC,cAAc,CAEzD,CAAC;AAEF,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAC9B,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAChC,kBAAkB,CAAC,CAAC,CAAC,CAAC;AACzB,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAC9B,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,EACxB,eAAe,CAAC,EACZ,IAAI,GACJ,SAAS,GACT,cAAc,CAAC,SAAS,CAAC,GACzB,cAAc,GACjB,kBAAkB,CAAC,CAAC,CAAC,CAAC"}
|
package/loadable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Component } from 'react';
|
|
3
|
-
const
|
|
3
|
+
const DefaultLoadingComponent = () => null;
|
|
4
4
|
const loadingStates = new WeakMap();
|
|
5
5
|
const getLoadingState = (loadFn, modify) => {
|
|
6
6
|
if (!loadingStates.has(loadFn)) {
|
|
@@ -46,7 +46,7 @@ class LoadableComponentBase extends Component {
|
|
|
46
46
|
constructor(config, props) {
|
|
47
47
|
super(props);
|
|
48
48
|
this.config = config;
|
|
49
|
-
this.state = getLoadingState(config.
|
|
49
|
+
this.state = getLoadingState(config.load);
|
|
50
50
|
}
|
|
51
51
|
static loadFn = undefined;
|
|
52
52
|
static preload() {
|
|
@@ -56,15 +56,15 @@ class LoadableComponentBase extends Component {
|
|
|
56
56
|
if (!this.state.loading) {
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
-
const { promise } = load(this.config.
|
|
60
|
-
this.setState(getLoadingState(this.config.
|
|
59
|
+
const { promise } = load(this.config.load);
|
|
60
|
+
this.setState(getLoadingState(this.config.load));
|
|
61
61
|
promise.finally(() => {
|
|
62
|
-
this.setState(getLoadingState(this.config.
|
|
62
|
+
this.setState(getLoadingState(this.config.load));
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
render() {
|
|
66
|
-
const { loader, throwOnError } = this.config;
|
|
67
|
-
const Loader = loader ||
|
|
66
|
+
const { loading, loader, throwOnError } = this.config;
|
|
67
|
+
const Loader = loading || loader || DefaultLoadingComponent;
|
|
68
68
|
if (throwOnError && this.state.error) {
|
|
69
69
|
throw this.state.error;
|
|
70
70
|
}
|
|
@@ -93,17 +93,26 @@ class LoadableComponentBase extends Component {
|
|
|
93
93
|
export const loadableDefaultConfig = {
|
|
94
94
|
throwOnError: false,
|
|
95
95
|
};
|
|
96
|
-
export function loadable(
|
|
97
|
-
const config =
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
export function loadable(...args) {
|
|
97
|
+
const config = {
|
|
98
|
+
...loadableDefaultConfig,
|
|
99
|
+
};
|
|
100
|
+
if (args.length === 1) {
|
|
101
|
+
Object.assign(config, args[0]);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
config.load = args[0];
|
|
105
|
+
if (typeof args[1] === 'function') {
|
|
106
|
+
config.loading = args[1];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
Object.assign(config, args[1] || {});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
100
112
|
class LoadableComponent extends LoadableComponentBase {
|
|
101
|
-
static loadFn =
|
|
113
|
+
static loadFn = config.load;
|
|
102
114
|
constructor(props) {
|
|
103
|
-
super(
|
|
104
|
-
loadFn,
|
|
105
|
-
...config,
|
|
106
|
-
}, props);
|
|
115
|
+
super(config, props);
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
return LoadableComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-simple-loadable",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
4
4
|
"description": "Really simple React Loadable component",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"react": "^
|
|
20
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "^18.3.18",
|