Skip to content
built by Mainmatter
A stylized sheepdog A stylized sheepdog

@sheepdog/svelte

Your async expert (and such a good boy)

Task management made simple

Sheepdog helps you maintain your async tasks and gives you useful derived state in your Svelte app.

Because managing tasks shouldn't feel like chasing sheep.

Code

<script>
import { task, timeout } from '@sheepdog/svelte';
let searchTask = task.restart(async function(value) {
await timeout(500);
let response = await fetch('/my-favourite-sheep?search=' + value);
return await response.json();
});
</script>
<label for="search">Search</label>
<input
name="search"
type="text"
on:input={(event) => searchTask.perform(event.target.value)}
/>
{#if $searchTask.isRunning}
Loading...
{:else if $searchTask.lastSuccessful?.value.length}
<ul>
{#each $searchTask.lastSuccesful.value as name}
<li>{name}</li>
{/each}
</ul>
{:else}
No sheep found
{/if}

Demo

  • Autumn
  • Buttercup
  • Chloe
  • Dolly
  • Emma
  • Freddie

Task modifiers

Specify what your task should do if there's another instance already running.

You can click an individual task instance to cancel it