import { ApiError } from './api'; /** A page's remote data: value, error code, reload. */ export class Remote { value = $state(null); error = $state(null); loading = $state(true); constructor(private fetcher: () => Promise) {} async load() { this.loading = true; try { this.value = await this.fetcher(); this.error = null; } catch (e) { this.error = e instanceof ApiError ? e.code : 'internal'; } finally { this.loading = false; } } }