Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Promised one-time watch for @vue/reactivity

License

NotificationsYou must be signed in to change notification settings

vue-reactivity/when

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promised one time watch for@vue/reactivity

npmnpm bundle size

Install

npm i @vue-reactivity/when

If you are making Vue applications, trywhen in VueUse instead.

Usage

Wait for some async data to be ready

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!

Wait for custom conditions

You can useinvoke 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!')})

Timeout

// 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}

More Examples

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

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp