package.src.nextTick.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alpinejs Show documentation
Show all versions of alpinejs Show documentation
The rugged, minimal JavaScript framework
let tickStack = []
let isHolding = false
export function nextTick(callback = () => {}) {
queueMicrotask(() => {
isHolding || setTimeout(() => {
releaseNextTicks()
})
})
return new Promise((res) => {
tickStack.push(() => {
callback();
res();
});
})
}
export function releaseNextTicks() {
isHolding = false
while (tickStack.length) tickStack.shift()()
}
export function holdNextTicks() {
isHolding = true
}