-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c011e0b
commit ef2ea8a
Showing
13 changed files
with
830 additions
and
161 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import { ReactNode, Component } from 'react'; | ||
|
||
interface ErrorBoundaryProps { | ||
fallback: ReactNode; | ||
onError: (error: Error) => void; | ||
} | ||
|
||
interface ErrorBoundaryState { | ||
hasError: boolean; | ||
} | ||
|
||
export default class ErrorBoundary extends Component<ErrorBoundaryProps> { | ||
state: ErrorBoundaryState = { hasError: false }; | ||
|
||
static getDerivedStateFromError(): ErrorBoundaryState { | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: Error): void { | ||
const { onError } = this.props; | ||
onError(error); | ||
} | ||
|
||
render(): ReactNode { | ||
const { fallback, children } = this.props; | ||
const { hasError } = this.state; | ||
|
||
return hasError ? fallback : children; | ||
} | ||
} |
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,9 @@ | ||
import React, { ReactNode } from 'react'; | ||
|
||
const mockRender = jest.fn((value: ReactNode) => ( | ||
<span> | ||
{value} | ||
</span> | ||
)); | ||
|
||
export default mockRender; |
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,13 @@ | ||
import React, { ComponentType, ReactNode } from 'react'; | ||
import Id from '../Context/Id'; | ||
import Context, { useContext } from '../Context'; | ||
|
||
const withContext: ( | ||
context: Context<ReactNode> | ||
) => ComponentType<{ id?: Id }> = (context) => ({ id = null }) => ( | ||
<div> | ||
{useContext(context, id)} | ||
</div> | ||
); | ||
|
||
export default withContext; |
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,13 @@ | ||
import React, { ComponentType, ReactNode } from 'react'; | ||
import Id from '../Context/Id'; | ||
import Service, { useService } from '../Service'; | ||
|
||
const withService: ( | ||
service: Service<any, ReactNode> | ||
) => ComponentType<{ id?: Id }> = (service) => ({ id = null }) => ( | ||
<div> | ||
{useService(service, id)} | ||
</div> | ||
); | ||
|
||
export default withService; |
Oops, something went wrong.