Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1619 from pmkroeker/master
Add types for Suspense/lazy
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
createElement, | ||
Component, | ||
} from "../.."; | ||
|
||
export interface LazyProps { | ||
isProp: boolean; | ||
} | ||
|
||
interface LazyState { | ||
forState: string; | ||
} | ||
export default class IsLazyComponent extends Component<LazyProps, LazyState> { | ||
render ({ isProp }: LazyProps) { | ||
return ( | ||
<div>{ | ||
isProp ? | ||
'Super Lazy TRUE' : | ||
'Super Lazy FALSE' | ||
}</div> | ||
) | ||
} | ||
} |
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,42 @@ | ||
import "mocha"; | ||
import { expect } from "chai"; | ||
import { | ||
createElement, | ||
Component, | ||
Suspense, | ||
lazy, | ||
} from "../.."; | ||
|
||
interface LazyProps { | ||
isProp: boolean; | ||
} | ||
|
||
const IsLazyFunctional = (props: LazyProps) => | ||
<div>{ | ||
props.isProp ? | ||
'Super Lazy TRUE' : | ||
'Super Lazy FALSE' | ||
}</div> | ||
|
||
const FallBack = () => <div>Still working...</div>; | ||
/** | ||
* Have to mock dynamic import as import() throws a syntax error in the test runner | ||
*/ | ||
const componentPromise = new Promise<{default: typeof IsLazyFunctional}>(resolve=>{ | ||
setTimeout(()=>{ | ||
resolve({ default: IsLazyFunctional}); | ||
},800); | ||
}); | ||
|
||
/** | ||
* For usage with import: | ||
* const IsLazyComp = lazy(() => import('./lazy')); | ||
*/ | ||
const IsLazyFunc = lazy(() => componentPromise); | ||
|
||
// Suspense using lazy component | ||
class SuspensefulFunc extends Component { | ||
render() { | ||
return <Suspense fallback={<FallBack/>}><IsLazyFunc isProp={false} /></Suspense> | ||
} | ||
} |