···11+/*
22+ * src: github.com/JLarky/react-lazily/blob/main/src/core/lazily.ts
33+ *
44+ * MIT License
55+ * Copyright (c) 2020 JLarky
66+ *
77+ * Permission is hereby granted, free of charge, to any person obtaining a copy
88+ * of this software and associated documentation files (the "Software"), to deal
99+ * in the Software without restriction, including without limitation the rights
1010+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111+ * copies of the Software, and to permit persons to whom the Software is
1212+ * furnished to do so, subject to the following conditions:
1313+ *
1414+ * The above copyright notice and this permission notice shall be included in all
1515+ * copies or substantial portions of the Software.
1616+ *
1717+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2020+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2121+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323+ SOFTWARE.
2424+ *
2525+ */
2626+2727+import { lazy } from "react";
2828+2929+export const lazily = <T extends {}, U extends keyof T>(loader: (x?: string) => Promise<T>) =>
3030+ new Proxy({} as unknown as T, {
3131+ get: (_target, componentName: string | symbol) => {
3232+ if (typeof componentName === "string") {
3333+ return lazy(() =>
3434+ loader(componentName).then((x) => ({
3535+ default: x[componentName as U] as any as React.ComponentType<any>,
3636+ })),
3737+ );
3838+ }
3939+ },
4040+ });