]> git.r.bdr.sh - rbdr/forum/blame_incremental - src/lib/stores/response_builder.ts
Don't remember what this WIP was about
[rbdr/forum] / src / lib / stores / response_builder.ts
... / ...
CommitLineData
1/**
2 * Utilities to build responses
3 */
4
5interface AnyError {
6 message: string;
7}
8
9export type StoreState<Type> = {
10 loading: boolean;
11 data: Type | void;
12 error: AnyError | void;
13};
14
15export function initialResponse<T>(initialState: T): StoreState<T> {
16 return {
17 loading: true,
18 data: initialState,
19 error: undefined
20 };
21}
22
23export function errorResponse<T>(error: AnyError): StoreState<T> {
24 return {
25 loading: false,
26 data: undefined,
27 error
28 };
29}
30
31export function response<T>(data: T): StoreState<T> {
32 return {
33 loading: false,
34 data,
35 error: undefined
36 };
37}