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