-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(uselazy): rewrite internals by just handle an array of dynam…
…ic imports instead of handling a function's return value, is more simple just handle and array of functions and resolve its promises using Promise.all BREAKING CHANGE: now useLazy takes and array of functions instead of a single one.
- Loading branch information
1 parent
9399c5c
commit 3059e0f
Showing
5 changed files
with
106 additions
and
64 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,23 +1,25 @@ | ||
export const FETCH_INIT = 'FETCH_INIT'; | ||
export const FETCH_SUCCESS = 'FETCH_SUCCESS'; | ||
export const FETCH_FAILURE = 'FETCH_FAILURE'; | ||
export const IMPORT_INIT = 'IMPORT_INIT'; | ||
export const IMPORT_SUCCESS = 'IMPORT_SUCCESS'; | ||
export const IMPORT_FAILURE = 'IMPORT_FAILURE'; | ||
|
||
interface DefaultImport<T> { | ||
export interface DefaultImport<T> { | ||
default: T; | ||
} | ||
|
||
export interface GetModule<T> { | ||
(): Promise<DefaultImport<T>> | Array<Promise<DefaultImport<T>>>; | ||
export interface ImportFn<T> { | ||
(): Promise<DefaultImport<T>>; | ||
} | ||
|
||
export type Result<T> = T | Array<T> | null | Error; | ||
// union type with `null` cuz' is the defaults | ||
// and `undefined` cuz' it's something that might be returned from `Array.prototype.pop` | ||
// when there's a single element on the modules array, so Typescript gets mad about it. | ||
export type Result<T> = T | Array<T | undefined> | null | Error | undefined; | ||
|
||
export interface State<T> { | ||
isLoading: boolean; | ||
result: Result<T>; | ||
} | ||
|
||
export type Action<T> = | ||
| { readonly type: typeof FETCH_INIT } | ||
| { readonly type: typeof FETCH_SUCCESS; payload: Result<T> } | ||
| { readonly type: typeof FETCH_FAILURE; payload: Result<T> }; | ||
| { readonly type: typeof IMPORT_INIT } | ||
| { readonly type: typeof IMPORT_SUCCESS; payload: Result<T> } | ||
| { readonly type: typeof IMPORT_FAILURE; payload: Result<T> }; |
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,5 @@ | ||
import { DefaultImport } from '../types'; | ||
|
||
export default function handleImport<T>(obj?: DefaultImport<T>): T | undefined { | ||
return obj && obj.default; | ||
} |