use-until
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

use-until

Promised one-time watch for changes

NPM version Codacy Badge Test coverage npm download gzip License

Sonar

Installing

# use pnpm
$ pnpm install use-until

# use npm
$ npm install use-until --save

# use yarn
$ yarn add use-until

Usage

1. Wait for some async data to be ready

import { ref } from 'vue'
import until from 'use-until'

const val = ref(1)

setTimeout(() => {
  val.value = 2
}, 1000)
;(async () => {
  await until(val).toBe(2)
  // state is now ready
})()

2. Wait for custom conditions

import { ref } from 'vue'
import until from 'use-until'

const val = ref(1)

setTimeout(() => {
  val.value = 2
}, 1000)
;(async () => {
  await until(val).toMatch(value => value > 1)
  // state is now ready
})()

3. Wait until timeout

import { ref } from 'vue'
import until from 'use-until'

const val = ref(1)

setTimeout(() => {
  val.value = 2
}, 1000)
;(async () => {
  await until(val).not.toBe(ref(2), { timeout: 500, throwOnTimeout: true })
  // reject timeout
})()

4. More Examples

import { ref } from 'vue'
import until from 'use-until'

const val = ref(1)

setTimeout(() => {
  val.value = 2
}, 1000)
;(async () => {
  await until(ref).toBe(true)
  await until(ref).toMatch(v => v > 5 && v < 10)
  await until(ref).changed()
  await until(ref).changedTimes(2)
  await until(ref).toBeTruthy()
  await until(ref).toBeNull()

  await until(ref).not.toBeNull()
  await until(ref).not.toBeTruthy()
})()

5. Use CDN resource

<script src="https://unpkg.com/vue-demi@latest/lib/index.iife.js"></script>
<script src="https://unpkg.com/use-until@latest/dist/index.global.prod.js"></script>
<script>
  await useUntil(val).toBe(true)
  // ...
</script>

Support & Issues

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i use-until

Weekly Downloads

2

Version

1.5.1

License

MIT

Unpacked Size

37.2 kB

Total Files

11

Last publish

Collaborators

  • saqqdy