Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jill64/async-observer
🔠Make Promise state observable as a string for svelte
https://github.com/jill64/async-observer
oberservable promise svelte utility
Last synced: 5 days ago
JSON representation
🔠Make Promise state observable as a string for svelte
- Host: GitHub
- URL: https://github.com/jill64/async-observer
- Owner: jill64
- License: mit
- Created: 2023-09-08T14:50:57.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-21T20:24:54.000Z (25 days ago)
- Last Synced: 2024-10-22T14:47:39.339Z (24 days ago)
- Topics: oberservable, promise, svelte, utility
- Language: TypeScript
- Homepage: https://npmjs.com/package/@jill64/async-observer
- Size: 406 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jill64/async-observer
🔠Make Promise state observable as a string for svelte
## Example
```js
import { observable } from '@jill64/async-observer'const { status, observed } = observable({
// FULFILLED => IDLE at 100ms
resolveToIdle: 100,
// REJECTED => IDLE at 500ms
rejectToIdle: 500
})const run = observed(async () => {
// e.g. Duration as 1000ms
await yourAsyncFunction()
})let str = ''
status.subscribe((status) => {
str = status
})// str => IDLE
run()
// str => PENDING
// ↓ After the 1000ms
// str => FULFILLED
// ↓ After the 100ms
// str => IDLE
```## Compatibility for svelte store
Since `status` is implemented according to svelte store, it can be used in svelte applications as follows
```svelte
import { observable } from '@jill64/async-observer'
const { status, observed } = observable()
$: set = observed(async () => {
await yourAsyncFunction()
})Button
{$status}
```## License
[MIT](LICENSE)