1.2.4 ā€¢ Published 1 month ago

@jill64/async-observer v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@jill64/async-observer

šŸ”­ Make Promise state observable as a string

Example

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

<script>
  import { observable } from '@jill64/async-observer'

  const { status, observed } = observable()

  $: set = observed(async () => {
    await yourAsyncFunction()
  })
</script>

<button on:click={set}>Button</button>

<div>{$status}</div>

License

MIT

1.2.4

1 month ago

1.2.3

3 months ago

1.2.2

5 months ago

1.2.0

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago