Skip to content

Commit

Permalink
fix: bad implement of untilElementAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-0x447f authored and Jack-Works committed Nov 22, 2019
1 parent 2fcc11e commit 0121a0a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { LiveSelector } from '@holoflows/kit'
import { IntervalWatcher, LiveSelector } from '@holoflows/kit'
import { isUndefined } from 'lodash-es'

export const untilElementAvailable = async (ls: LiveSelector<HTMLElement, boolean>) => {
const w = new IntervalWatcher(ls)
return new Promise<void>((resolve, reject) => {
let timedOut = false
setTimeout(() => (timedOut = true), 4000)
const t = setInterval(() => {
if (ls.evaluate()) {
clearInterval(t)
resolve()
}
if (timedOut) {
clearInterval(t)
reject()
}
}, 500)
setTimeout(() => reject(), 5000)
w.useForeach(() => {
w.stopWatch()
resolve()
}).startWatch(500)
})
}

Expand Down

0 comments on commit 0121a0a

Please sign in to comment.