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

mock-db.ts

28 lines521 Bytes

1export function sleep(ms: number) {
2 return new Promise((resolve) => setTimeout(resolve, ms))
3}
4​
5export interface StoredUser {
6 firstName: string
7 lastName: string
8}
9​
10class DB {
11 private data: StoredUser = {
12 firstName: 'FirstName',
13 lastName: 'LastName',
14 }
15​
16 async getData(): Promise<StoredUser> {
17 await sleep(1000)
18 return { ...this.data }
19 }
20​
21 async saveUser(value: StoredUser): Promise<StoredUser> {
22 await sleep(1000)
23 this.data = value
24 return value
25 }
27​
28export const db = new DB()