From 0121a0ad49e2c3e8a98a2f8271e0a0f030c6ee6b Mon Sep 17 00:00:00 2001 From: Misaka Kumomi <447f.misaka@outlook.com> Date: Fri, 8 Nov 2019 08:39:55 +0800 Subject: [PATCH] fix: bad implement of untilElementAvailable --- src/utils/dom.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 715b6c02693f..b351044a8173 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -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) => { + const w = new IntervalWatcher(ls) return new Promise((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) }) }