Giter Site home page Giter Site logo

cicerchie / svelte-swr Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 101 KB

Stale-while-revalidate data fetching library for Svelte.

License: MIT License

JavaScript 22.29% HTML 4.44% Svelte 1.94% TypeScript 71.34%
svelte swr stale-while-revalidate svelte-swr datafetching

svelte-swr's Introduction

Cicerchie Svelte-SWR

A stale-while-revalidate data fetching library for Svelte.


Lastest release License Github repo dependents Github pkg dependents Github open issues Github status Bundlephobia MinZip Bundlephobia dependency count Snyk Npm version Npm DT Npm dependents Npm types David DM dep David DM dev-dep David DM peer-dep


WARNING!

These components are still "experimental" (v0.x.x).
Some of them are not tested as rigourously as it should be and none of them have been through code review.
Use them at your own risk and check that them do what you want them to do.


Installation

npm install @cicerchie/svelte-swr

Usage

<script>
  import { useSWR } from "@cicerchie/svelte-swr";

  const players = useSWR<PlayerList>();

  $: players.update({
    key: `players?page=${page}&filter=${JSON.stringify(filter)}`,
    fn: () => playersService.list({ page, filter }),
  });
</script>

{#if $players.isLoading}
  Loading...
{:else if $players.error}
  {$players.error}
{:else}
  {#each $players.data.players as player (player.id)}
    ID: {player.id}
  {:else}
    No players yet
  {/each}
{/if}

Changelog

Is automagically updated with each release and you can read it here.

Features

  • Transport and protocol agnostic
  • Jamstack oriented
  • Fast, lightweight and reusable data fetching (fast page navigation, fast UI)
  • Built-in cache
  • Cache data and retrieve it when needed
  • Initial immediate data (offline or already cached)
  • Global onError custom handler
  • Typescript ready (still incomplete and so many any!)
  • Pagination (done, docs needed)
  • Requests deduplication
  • Enable and disable it with a prop
  • Polling on interval
  • Revalidation on window focus
  • Revalidation on network recovery
  • Local mutation (Optimistic UI)
  • Smart error retry
  • Scroll position recovery
  • Persist and restore from LocalStorage/IndexedDB
  • Clear cache when you need to invalidate all data or specific keys

TODO

  • Docs (HELP!)
  • Tests (HELP!)
  • Demo site (using routes dir: it's a SvelteKit app!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.