UNPKG

valync

Version:

**A lightweight, framework-agnostic async data handling library for React & Vue, inspired by Riverpod’s AsyncValue pattern and powered by ts-results-es.**

43 lines 1.09 kB
// Normalize cache key (convert object to stable string) export function normalizeKey(key) { return typeof key === "string" ? key : JSON.stringify(key); } // Base abstract class for async stZte export class AsyncValue { isLoading() { return this instanceof AsyncLoading; } isData() { return this instanceof AsyncData; } isError() { return this instanceof AsyncError; } } // Represents loading state export class AsyncLoading extends AsyncValue { when(h) { return h.loading ? h.loading() : undefined; } } // Represents failed state with error export class AsyncError extends AsyncValue { constructor(error) { super(); this.error = error; } when(h) { return h.error ? h.error(this.error) : undefined; } } // Represents data state—with Some(T) or None export class AsyncData extends AsyncValue { constructor(value) { super(); this.value = value; } when(h) { return h.data ? h.data(this.value) : undefined; } } //# sourceMappingURL=index.js.map