-
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
Showing
5 changed files
with
81 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from "react" | ||
import { connect } from "react-redux" | ||
import { State } from "model" | ||
|
||
export interface ErrorDisplayProps { | ||
latestError: string | undefined | ||
} | ||
|
||
export class ErrorDisplay extends React.Component<ErrorDisplayProps, void> { | ||
public render() { | ||
return ( | ||
<div> | ||
{this.props.latestError} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
function mapStateToProps(state: State): ErrorDisplayProps { | ||
return { | ||
latestError: state.errors.latestError, | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(ErrorDisplay) |
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,43 @@ | ||
import { Action as ReduxAction, MiddlewareAPI } from "redux" | ||
import { | ||
State, | ||
} from "model" | ||
import actionCreator, { isType, Action } from "redux-typescript-actions" | ||
import { ActionsObservable } from "redux-observable" | ||
|
||
export interface ErrorsState { | ||
latestError?: string, | ||
} | ||
|
||
export const NEW_ERROR = actionCreator<string>("NEW_ERROR") | ||
|
||
interface ET { | ||
[key: string]: (x: ReduxAction) => string | undefined | ||
} | ||
|
||
|
||
// Add to this object to add more error translations | ||
export const errorTranslators: ET = {} | ||
|
||
export const errorsEpic = (action$: ActionsObservable<ReduxAction>, store: MiddlewareAPI<State>) => | ||
action$ | ||
.map<ReduxAction, Action<string> | undefined>(x => { | ||
const f = errorTranslators[x.type] | ||
if (f !== undefined) { | ||
const fx = f(x) | ||
if (fx !== undefined) { | ||
return NEW_ERROR(fx) | ||
} | ||
} | ||
}) | ||
.filterUndefined() | ||
|
||
|
||
export const errors = (state = {}, action: ReduxAction): ErrorsState => { | ||
if (isType(action, NEW_ERROR)) { | ||
return { | ||
latestError: action.payload, | ||
} | ||
} | ||
return state | ||
} |
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