Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jill64/svelte-observer

🔭 Library for Svelte to make Promise status easily observable from outside
https://github.com/jill64/svelte-observer

observer promise svelte

Last synced: 7 days ago
JSON representation

🔭 Library for Svelte to make Promise status easily observable from outside

Awesome Lists containing this project

README

        

# @jill64/svelte-observer

npm-version npm-license npm-download-month npm-min-size ci.yml website

🔭 Library for Svelte to make Promise status easily observable from outside

## [Demo](https://svelte-observer.jill64.dev)

## Installation

```bash
npm i @jill64/svelte-observer
```

## Usage

```svelte

import { observable } from '@jill64/svelte-observer'

// Define the asynchronous function you want to observe
const wait1Sec = async () => {
await new Promise((resolve) => setTimeout(resolve, 1000))
}
const wait1SecThrow = async () => {
await new Promise((resolve) => setTimeout(resolve, 1000))
throw new Error('Expected Error')
} // Create Proxy

let { status, observed } = $derived(observable())

// Define proxied functions
let observedWait1Sec = $derived(observed(wait1Sec))
let observedWait1SecThrow = $derived(observed(wait1SecThrow))

Success

Error

{status}
```

## License

[MIT](LICENSE)