Skip to content

saqqdy/untiljs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

untiljs

Promised one-time watch for changes

NPM version Codacy Badge tree shaking typescript Test coverage npm download gzip License

Sonar

Read this in other languages: English | 简体中文

Experience online

Experience the untiljs features online Edit in CodeSandbox

Installing

# use pnpm
$ pnpm install untiljs

# use npm
$ npm install untiljs --save

# use yarn
$ yarn add untiljs

Usage

1. Wait for some async data to be ready

import { ref } from 'vue'
import until from 'untiljs'

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 'untiljs'

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 'untiljs'

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 'untiljs'

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()
})()

Using unpkg CDN

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

Support & Issues

Please open an issue here.

License

MIT