( ctrl: Controller<any>, props: ControllerQueue[number], isLoop?: boolean )
| 344 | * stopped or cancelled. |
| 345 | */ |
| 346 | export 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, |
no test coverage detected
searching dependent graphs…