next-tick.ts — vue Source File
Architecture documentation for next-tick.ts, a typescript file in the vue codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR bf792703_842a_50eb_c357_a2c1c61e235e["next-tick.ts"] 88dc54e4_4a50_ce50_5fb5_52118613323e["error.ts"] bf792703_842a_50eb_c357_a2c1c61e235e --> 88dc54e4_4a50_ce50_5fb5_52118613323e 09b66670_60c6_d4f1_48f9_8f5538b7633e["handleError"] bf792703_842a_50eb_c357_a2c1c61e235e --> 09b66670_60c6_d4f1_48f9_8f5538b7633e aa2b6238_64b5_d2a0_65ca_67fd6aa3bf04["env.ts"] bf792703_842a_50eb_c357_a2c1c61e235e --> aa2b6238_64b5_d2a0_65ca_67fd6aa3bf04 2765e7dc_2ce5_fc15_c947_e6e5056985da["isNative"] bf792703_842a_50eb_c357_a2c1c61e235e --> 2765e7dc_2ce5_fc15_c947_e6e5056985da 09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"] bf792703_842a_50eb_c357_a2c1c61e235e --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b style bf792703_842a_50eb_c357_a2c1c61e235e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/* globals MutationObserver */
import { noop } from 'shared/util'
import { handleError } from './error'
import { isIE, isIOS, isNative } from './env'
export let isUsingMicroTask = false
const callbacks: Array<Function> = []
let pending = false
function flushCallbacks() {
pending = false
const copies = callbacks.slice(0)
callbacks.length = 0
for (let i = 0; i < copies.length; i++) {
copies[i]()
}
}
// Here we have async deferring wrappers using microtasks.
// In 2.5 we used (macro) tasks (in combination with microtasks).
// However, it has subtle problems when state is changed right before repaint
// (e.g. #6813, out-in transitions).
// Also, using (macro) tasks in event handler would cause some weird behaviors
// that cannot be circumvented (e.g. #7109, #7153, #7546, #7834, #8109).
// So we now use microtasks everywhere, again.
// A major drawback of this tradeoff is that there are some scenarios
// where microtasks have too high a priority and fire in between supposedly
// sequential events (e.g. #4521, #6690, which have workarounds)
// or even between bubbling of the same event (#6566).
let timerFunc
// The nextTick behavior leverages the microtask queue, which can be accessed
// via either native Promise.then or MutationObserver.
// MutationObserver has wider support, however it is seriously bugged in
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
// completely stops working after triggering a few times... so, if native
// Promise is available, we will use it:
/* istanbul ignore next, $flow-disable-line */
if (typeof Promise !== 'undefined' && isNative(Promise)) {
const p = Promise.resolve()
timerFunc = () => {
p.then(flushCallbacks)
// In problematic UIWebViews, Promise.then doesn't completely break, but
// it can get stuck in a weird state where callbacks are pushed into the
// microtask queue but the queue isn't being flushed, until the browser
// needs to do some other work, e.g. handle a timer. Therefore we can
// "force" the microtask queue to be flushed by adding an empty timer.
if (isIOS) setTimeout(noop)
}
isUsingMicroTask = true
} else if (
!isIE &&
typeof MutationObserver !== 'undefined' &&
(isNative(MutationObserver) ||
// PhantomJS and iOS 7.x
MutationObserver.toString() === '[object MutationObserverConstructor]')
) {
// Use MutationObserver where native Promise is not available,
// e.g. PhantomJS, iOS7, Android 4.4
// (#6466 MutationObserver is unreliable in IE11)
let counter = 1
const observer = new MutationObserver(flushCallbacks)
const textNode = document.createTextNode(String(counter))
observer.observe(textNode, {
characterData: true
})
timerFunc = () => {
counter = (counter + 1) % 2
textNode.data = String(counter)
}
isUsingMicroTask = true
} else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
// Fallback to setImmediate.
// Technically it leverages the (macro) task queue,
// but it is still a better choice than setTimeout.
timerFunc = () => {
setImmediate(flushCallbacks)
}
} else {
// Fallback to setTimeout.
timerFunc = () => {
setTimeout(flushCallbacks, 0)
}
}
export function nextTick(): Promise<void>
export function nextTick<T>(this: T, cb: (this: T, ...args: any[]) => any): void
export function nextTick<T>(cb: (this: T, ...args: any[]) => any, ctx: T): void
/**
* @internal
*/
export function nextTick(cb?: (...args: any[]) => any, ctx?: object) {
let _resolve
callbacks.push(() => {
if (cb) {
try {
cb.call(ctx)
} catch (e: any) {
handleError(e, ctx, 'nextTick')
}
} else if (_resolve) {
_resolve(ctx)
}
})
if (!pending) {
pending = true
timerFunc()
}
// $flow-disable-line
if (!cb && typeof Promise !== 'undefined') {
return new Promise(resolve => {
_resolve = resolve
})
}
}
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does next-tick.ts do?
next-tick.ts is a source file in the vue codebase, written in typescript. It belongs to the VueCore domain, GlobalAPI subdomain.
What functions are defined in next-tick.ts?
next-tick.ts defines 3 function(s): flushCallbacks, nextTick, timerFunc.
What does next-tick.ts depend on?
next-tick.ts imports 5 module(s): env.ts, error.ts, handleError, isNative, util.
Where is next-tick.ts in the architecture?
next-tick.ts is located at src/core/util/next-tick.ts (domain: VueCore, subdomain: GlobalAPI, directory: src/core/util).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free