Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

mock-db.ts

32 lines581 Bytes

1export async function sleep(ms: number) {
2 return new Promise((res) => setTimeout(res, ms))
3}
4​
5export interface StoredUser {
6 firstName: string
7 lastName: string
8}
9​
10class DB {
11 private data: StoredUser
12​
13 constructor() {
14 this.data = { firstName: 'FirstName', lastName: 'LastName' }
15 }
16​
17 async getData(): Promise<StoredUser> {
18 await sleep(1000)
19 return { ...this.data }
20 }
21​
22 async saveUser(value: StoredUser) {
23 await sleep(1000)
24 this.data = value
25 return value
26 }
28​
29/**
30 * Dummy Database to emulate server-side actions
31 */
32export const db = new DB()