hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { createResource as createSolidResource } from "solid-js"; |
| 2 | |
| 3 | /** |
| 4 | * `createResource` whose accessor suspends only until the first value lands. |
| 5 | * |
| 6 | * Solid's bare `resource()` re-suspends on every refetch and every source |
| 7 | * change, so the nearest `<Suspense>` swaps its whole subtree for the fallback: |
| 8 | * deleting one table row or saving a panel blanked the table card, header, |
| 9 | * search and pager, and reset the table's own page and query. Reading |
| 10 | * `resource.latest` instead keeps the last value on screen while the next one |
| 11 | * loads — only the rows change when it arrives. |
| 12 | * |
| 13 | * Detail routes remount per `$id` (the router keys a match by its params), so |
| 14 | * holding the previous value never shows one record's data under another. |
| 15 | * `loading`, `error`, `state`, `latest`, `refetch` and `mutate` are unchanged. |
| 16 | */ |
| 17 | export const createResource = ((...args: unknown[]) => { |
| 18 | const [resource, actions] = (createSolidResource as unknown as (...a: unknown[]) => [Record<string, unknown> & (() => unknown), unknown])(...args); |
| 19 | const read = () => resource.latest; |
| 20 | for (const key of ["state", "loading", "error", "latest"] as const) { |
| 21 | Object.defineProperty(read, key, { get: () => resource[key] }); |
| 22 | } |
| 23 | return [read, actions]; |
| 24 | }) as typeof createSolidResource; |