blob: f43c4211bcd7e715942f733b394b49ba7ff120a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { Dispatch } from 'redux';
import { Action, actions } from '../redux/actions';
class ErrorFlasher {
private _timeoutId?: number;
public flashNewError(dispatch: Dispatch<Action>, error: any, delayMs: number = 7000): void {
this._clearTimeout();
// dispatch new message
dispatch(actions.setError(error));
this._timeoutId = window.setTimeout(() => {
dispatch(actions.hideError());
}, delayMs);
}
public clearError(dispatch: Dispatch<Action>): void {
this._clearTimeout();
dispatch(actions.hideError());
}
private _clearTimeout(): void {
if (this._timeoutId) {
window.clearTimeout(this._timeoutId);
}
}
}
export const errorFlasher = new ErrorFlasher();
|