hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB4e0a329Burak Boduroğlu2 months ago537 commits
| 1 | import { client } from "../client"; |
| 2 | import type { SchoolSettings } from "../client"; |
| 3 | |
| 4 | let cachedSettings: SchoolSettings | null = null; |
| 5 | let pendingSettings: Promise<SchoolSettings> | null = null; |
| 6 | |
| 7 | export function getSettings(signal?: AbortSignal): Promise<SchoolSettings> { |
| 8 | if (cachedSettings) return Promise.resolve(cachedSettings); |
| 9 | if (pendingSettings) return pendingSettings; |
| 10 | pendingSettings = client<SchoolSettings>("/settings", { signal }) |
| 11 | .then((settings) => { |
| 12 | cachedSettings = settings; |
| 13 | return settings; |
| 14 | }) |
| 15 | .finally(() => { |
| 16 | pendingSettings = null; |
| 17 | }); |
| 18 | return pendingSettings; |
| 19 | } |
| 20 | |
| 21 | export function setCachedSettings(settings: SchoolSettings): void { |
| 22 | cachedSettings = settings; |
| 23 | pendingSettings = null; |
| 24 | } |