MCPcopy
hub / github.com/vuejs/core / whenTransitionEnds

Function whenTransitionEnds

packages/runtime-dom/src/components/Transition.ts:348–387  ·  view source on GitHub ↗
(
  el: Element & { _endId?: number },
  expectedType: TransitionProps['type'] | undefined,
  explicitTimeout: number | null,
  resolve: () => void,
)

Source from the content-addressed store, hash-verified

346let endId = 0
347
348function whenTransitionEnds(
349 el: Element & { _endId?: number },
350 expectedType: TransitionProps['type'] | undefined,
351 explicitTimeout: number | null,
352 resolve: () => void,
353) {
354 const id = (el._endId = ++endId)
355 const resolveIfNotStale = () => {
356 if (id === el._endId) {
357 resolve()
358 }
359 }
360
361 if (explicitTimeout != null) {
362 return setTimeout(resolveIfNotStale, explicitTimeout)
363 }
364
365 const { type, timeout, propCount } = getTransitionInfo(el, expectedType)
366 if (!type) {
367 return resolve()
368 }
369
370 const endEvent = type + 'end'
371 let ended = 0
372 const end = () => {
373 el.removeEventListener(endEvent, onEnd)
374 resolveIfNotStale()
375 }
376 const onEnd = (e: Event) => {
377 if (e.target === el && ++ended >= propCount) {
378 end()
379 }
380 }
381 setTimeout(() => {
382 if (ended < propCount) {
383 end()
384 }
385 }, timeout + 1)
386 el.addEventListener(endEvent, onEnd)
387}
388
389interface CSSTransitionInfo {
390 type: AnimationTypes | null

Callers 2

makeEnterHookFunction · 0.85
onLeaveFunction · 0.85

Calls 3

getTransitionInfoFunction · 0.85
endFunction · 0.85
resolveFunction · 0.70

Tested by

no test coverage detected