blob: 1e122433eff60507f8e7376d996da3dbcb1339ba (
plain)
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
28
29
30
31
32
33
34
35
36
37
|
/**
* Utilities to build responses
*/
interface AnyError {
message: string
};
export type StoreState<Type> = {
loading: boolean;
data: Type | void;
error: AnyError | void;
};
export function initialResponse<T> (initialState: T): StoreState<T> {
return {
loading: true,
data: initialState,
error: undefined
};
}
export function errorResponse<T> (error: AnyError): StoreState<T> {
return {
loading: false,
data: undefined,
error
};
}
export function response<T> (data: T): StoreState<T> {
return {
loading: false,
data,
error: undefined
};
}
|