1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import * as React from "react";
|
9 |
|
10 | export interface DefaultImportedComponent<Props> {
|
11 | default: React.ComponentType<Props>;
|
12 | }
|
13 |
|
14 | export type DefaultComponent<Props> = React.ComponentType<Props> | DefaultImportedComponent<Props>;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export type ComponentResolver<Props, Module = DefaultComponent<Props>> = (
|
23 | module: Module,
|
24 | props: Props,
|
25 | ) => React.ComponentType<Props>;
|
26 |
|
27 | export interface OptionsWithoutResolver<Props> {
|
28 | cacheKey?(props: Props): any;
|
29 | fallback?: JSX.Element | undefined;
|
30 | ssr?: boolean | undefined;
|
31 | }
|
32 |
|
33 | export interface Options<Props, Module = DefaultComponent<Props>> extends OptionsWithoutResolver<Props> {
|
34 | resolveComponent?: ComponentResolver<Props, Module> | undefined;
|
35 | }
|
36 |
|
37 | export interface OptionsWithResolver<Props, Module = DefaultComponent<Props>> extends OptionsWithoutResolver<Props> {
|
38 | resolveComponent: ComponentResolver<Props, Module>;
|
39 | }
|
40 |
|
41 | export interface LoadableReadyOptions {
|
42 | namespace?: string | undefined;
|
43 | }
|
44 |
|
45 | export interface LoadableComponentMethods<Props> {
|
46 | preload(props?: Props): void;
|
47 | load(props?: Props): Promise<React.ComponentType<Props>>;
|
48 | }
|
49 |
|
50 | export interface ExtraComponentProps {
|
51 | fallback?: JSX.Element | undefined;
|
52 | }
|
53 |
|
54 | export type LoadableComponent<Props> =
|
55 | & React.ComponentType<Props & ExtraComponentProps>
|
56 | & LoadableComponentMethods<Props>;
|
57 |
|
58 | export interface ExtraClassComponentProps<Component extends React.ComponentClass> extends ExtraComponentProps {
|
59 | ref?: React.LegacyRef<InstanceType<Component>> | undefined;
|
60 | }
|
61 |
|
62 | export type LoadableClassComponent<Component extends React.ComponentClass> =
|
63 | & React.ComponentType<
|
64 | React.ComponentProps<Component> & ExtraClassComponentProps<Component>
|
65 | >
|
66 | & LoadableComponentMethods<React.ComponentProps<Component>>;
|
67 |
|
68 | export type LoadableLibrary<Module> =
|
69 | & React.ComponentType<{
|
70 | fallback?: JSX.Element | undefined;
|
71 | children?: ((module: Module) => React.ReactNode) | undefined;
|
72 | ref?: React.Ref<Module> | undefined;
|
73 | }>
|
74 | & Module
|
75 | & LoadableComponentMethods<object>;
|
76 |
|
77 | declare function lib<Props, Module>(
|
78 | loadFn: (props: Props) => Promise<Module>,
|
79 | options?: OptionsWithoutResolver<Props>,
|
80 | ): LoadableLibrary<Module>;
|
81 |
|
82 | declare function loadableFunc<Props, Module = DefaultComponent<Props>>(
|
83 | loadFn: (props: Props) => Promise<Module>,
|
84 | options: OptionsWithResolver<Props, Module>,
|
85 | ): LoadableComponent<Props>;
|
86 |
|
87 | declare function loadableFunc<Props>(
|
88 | loadFn: (props: Props) => Promise<DefaultComponent<Props>>,
|
89 | options?: OptionsWithoutResolver<Props>,
|
90 | ): LoadableComponent<Props>;
|
91 |
|
92 | declare function loadableFunc<Component extends React.ComponentClass<any>>(
|
93 | loadFn: (props: React.ComponentProps<Component>) => Promise<Component | { default: Component }>,
|
94 | options?: Options<React.ComponentProps<Component>, Component>,
|
95 | ): LoadableClassComponent<Component>;
|
96 |
|
97 | declare const loadable: typeof loadableFunc & { lib: typeof lib };
|
98 |
|
99 | export default loadable;
|
100 |
|
101 | export namespace lazy {
|
102 | function lib<Module>(loadFn: (props: object) => Promise<Module>): LoadableLibrary<Module>;
|
103 | }
|
104 |
|
105 | export function lazy<Props>(loadFn: (props: Props) => Promise<DefaultComponent<Props>>): LoadableComponent<Props>;
|
106 |
|
107 | export function loadableReady(done?: () => any, options?: LoadableReadyOptions): Promise<void>;
|
108 |
|
\ | No newline at end of file |