rune-query
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Rune Query

A library for handling asynchronous functions with Runes

.github/workflows/test.yaml

Usage

// in your svelte component or .svelte.js/ts files
let { query, invalidate } = createQuery(async (args) => { .../* some data to be fetched */ });

let q = query({ id: 123 });

// loading is true initially until the asynchronous function completes
q.loading;

// The data can be found in the data key
q.data;

// If an error is thrown in your function, it will be available under the error key
q.error;

// later, you may wish to invalidate the current data, and refetch
invalidate();
// That's it, the reactive `data` and `loading` values above will reactively update

Type inference

The type for data is inferred from the ReturnType of your async function. This means no manually typing expected types etc.

let { query } = createQuery(async () => 123);
query.data; // number | undefined
let { query } = createQuery(async () => "hello world");
query.data; // string | undefined

// when loading is complete, the data type will resolve to just the type (not undefined anymore)
if (!query.loading) {
  query.data; // string
}

Readme

Keywords

Package Sidebar

Install

npm i rune-query

Weekly Downloads

3

Version

0.0.5

License

ISC

Unpacked Size

9.34 kB

Total Files

6

Last publish

Collaborators

  • c-sinclair