- Notifications
You must be signed in to change notification settings - Fork2
Promised one-time watch for @vue/reactivity
License
NotificationsYou must be signed in to change notification settings
vue-reactivity/when
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Promised one time watch for@vue/reactivity
npm i @vue-reactivity/when
If you are making Vue applications, trywhen
in VueUse instead.
import{when}from'@vue-reactivity/when'const{ state, ready}=useAsyncState(fetch('https://jsonplaceholder.typicode.com/todos/1').then(t=>t.json()),{},)awaitwhen(ready).toBe(true)console.log(state)// state is now ready!
You can use
invoke
to call the async function.
import{when,invoke}from'@vue-reactivity/when'const{ count}=useMyCounter()invoke(async()=>{awaitwhen(count).toMatch(v=>v>7)alert('Counter is now larger than 7!')})
// will be resolve when ref.value === true or 1000ms passedawaitwhen(ref).toBe(true,{timeout:1000})// will throw if timeouttry{awaitwhen(ref).toBe(true,{timeout:1000,throwOnTimeout:true})// ref.value === true}catch(e){// timeout}
awaitwhen(ref).toBe(true)awaitwhen(ref).toMatch(v=>v>10&&v<100)awaitwhen(ref).changed()awaitwhen(ref).changedTimes(10)awaitwhen(ref).toBeTruthy()awaitwhen(ref).toBeNull()awaitwhen(ref).toBeNaN()awaitwhen(ref).toContain(5)awaitwhen(ref).not.toBeNull()awaitwhen(ref).not.toBeTruthy()
MIT
About
Promised one-time watch for @vue/reactivity