MCPcopy
hub / github.com/pmndrs/react-spring / flushUpdate

Function flushUpdate

packages/core/src/Controller.ts:346–502  ·  view source on GitHub ↗
(
  ctrl: Controller<any>,
  props: ControllerQueue[number],
  isLoop?: boolean
)

Source from the content-addressed store, hash-verified

344 * stopped or cancelled.
345 */
346export async function flushUpdate(
347 ctrl: Controller<any>,
348 props: ControllerQueue[number],
349 isLoop?: boolean
350): AsyncResult {
351 const { keys, to, from, loop, onRest, onResolve } = props
352 const defaults = is.obj(props.default) && props.default
353
354 // Looping must be handled in this function, or else the values
355 // would end up looping out-of-sync in many common cases.
356 if (loop) {
357 props.loop = false
358 }
359
360 // Top-level external calls bump the loop generation so an earlier loop
361 // chain can notice it has been superseded — but only when this update
362 // could express a different loop intent. Updates from `runAsync`'s
363 // internal `animate` carry a `parentId`, and pure lifecycle updates
364 // (`ctrl.pause()` / `ctrl.resume()`) don't mention `loop`; in both
365 // cases bumping would kill the very loop chain that scheduled them.
366 // Recursive iterations (isLoop) inherit the id from the props.
367 const propsAny = props as any
368 const isExternalLoopIntent = !isLoop && !propsAny.parentId && 'loop' in props
369 const loopId: number = isExternalLoopIntent
370 ? ++ctrl['_lastLoopId']
371 : isLoop
372 ? propsAny.loopId
373 : ctrl['_lastLoopId']
374
375 // Treat false like null, which gets ignored.
376 if (to === false) props.to = null
377 if (from === false) props.from = null
378
379 const asyncTo = is.arr(to) || is.fun(to) ? to : undefined
380 if (asyncTo) {
381 props.to = undefined
382 props.onRest = undefined
383 if (defaults) {
384 defaults.onRest = undefined
385 }
386 }
387 // For certain events, use batching to prevent multiple calls per frame.
388 // However, batching is avoided when the `to` prop is async, because any
389 // event props are used as default props instead.
390 else {
391 each(BATCHED_EVENTS, key => {
392 const handler: any = props[key]
393 if (is.fun(handler)) {
394 const queue = ctrl['_events'][key]
395 props[key] = (({ finished, cancelled }: AnimationResult) => {
396 const result = queue.get(handler)
397 if (result) {
398 if (!finished) result.finished = false
399 if (cancelled) result.cancelled = true
400 } else {
401 // The "value" is set before the "handler" is called.
402 queue.set(handler, {
403 value: null,

Callers 1

flushUpdateQueueFunction · 0.85

Calls 13

eachFunction · 0.90
flushCallsFunction · 0.90
getDefaultPropFunction · 0.90
schedulePropsFunction · 0.90
getCombinedResultFunction · 0.90
createLoopUpdateFunction · 0.90
fnFunction · 0.85
prepareKeysFunction · 0.85
addMethod · 0.80
forEachMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…