This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…and lazy loading
- Loading branch information
1 parent
b8ba9a2
commit 13fef91
Showing
5 changed files
with
30 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from './checkout/Checkout'; | ||
export * from './exampleui/ExampleUI'; | ||
export * from './hints/Hints'; | ||
export * from './subgraph/Subgraph'; | ||
import { lazier } from '~~/helpers/lazier'; | ||
|
||
export const ExampleUI = lazier(() => import('./exampleui/ExampleUI'), 'ExampleUI'); | ||
export const Checkout = lazier(() => import('./checkout/Checkout'), 'Checkout'); | ||
export const Subgraph = lazier(() => import('./subgraph/Subgraph'), 'Subgraph'); | ||
export const Hints = lazier(() => import('./hints/Hints'), 'Hints'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { lazy, ComponentType, LazyExoticComponent } from 'react'; | ||
|
||
/** | ||
* modified lazy | ||
* @param factory | ||
* @param name | ||
* @returns | ||
*/ | ||
export const lazier = <T extends ComponentType<any>>( | ||
factory: () => Promise<{ | ||
[name: string]: T; | ||
}>, | ||
name: string | ||
): LazyExoticComponent<T> => { | ||
return lazy(() => { | ||
return factory().then((module) => ({ default: module[name] })); | ||
}); | ||
}; |