/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import React, { lazy as reactLazy } from 'react'; type LazyComponentType, K extends keyof M> = { [P in K]: M[P]; }; export function lazy>(factory: () => Promise): M['default']; export function lazy, K extends keyof M = keyof M>( factory: () => Promise, ...componentNames: K[] ): LazyComponentType; export function lazy, K extends keyof M>( factory: () => Promise, ...componentNames: K[] ) { if (componentNames.length === 0) { const LazyComponent = reactLazy(() => factory().then((module) => ({ default: module.default, })), ); const Component = (props) => ( ); return Component; } return componentNames.reduce( (acc, name) => { const LazyComponent = reactLazy(() => factory().then((module) => ({ default: module[name], })), ); acc[name] = ((props) => ( )) as M[K]; return acc; }, {} as LazyComponentType, ); }