use-until
v1.5.1
Published
Promised one-time watch for changes
Downloads
5
Maintainers
Readme
use-until
Promised one-time watch for changes
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.