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

Function scheduleProps

packages/core/src/scheduleProps.ts:34–106  ·  view source on GitHub ↗
(
  callId: number,
  { key, props, defaultProps, state, actions }: ScheduledProps<T>
)

Source from the content-addressed store, hash-verified

32 * but the `pause` prop is taken care of.
33 */
34export function scheduleProps<T extends AnimationTarget>(
35 callId: number,
36 { key, props, defaultProps, state, actions }: ScheduledProps<T>
37): AsyncResult<T> {
38 return new Promise((resolve, reject) => {
39 let delay: number
40 let timeout: Timeout
41
42 let cancel = matchProp(props.cancel ?? defaultProps?.cancel, key)
43 if (cancel) {
44 onStart()
45 } else {
46 // The `pause` prop updates the paused flag.
47 if (!is.und(props.pause)) {
48 state.paused = matchProp(props.pause, key)
49 }
50 // The default `pause` takes precedence when true,
51 // which allows `SpringContext` to work as expected.
52 let pause = defaultProps?.pause
53 if (pause !== true) {
54 pause = state.paused || matchProp(pause, key)
55 }
56
57 delay = callProp(props.delay || 0, key)
58 if (pause) {
59 state.resumeQueue.add(onResume)
60 actions.pause()
61 } else {
62 actions.resume()
63 onResume()
64 }
65 }
66
67 function onPause() {
68 state.resumeQueue.add(onResume)
69 state.timeouts.delete(timeout)
70 timeout.cancel()
71 // Cache the remaining delay.
72 delay = timeout.time - raf.now()
73 }
74
75 function onResume() {
76 if (delay > 0 && !G.skipAnimation) {
77 state.delayed = true
78 timeout = raf.setTimeout(onStart, delay)
79 state.pauseQueue.add(onPause)
80 state.timeouts.add(timeout)
81 } else {
82 onStart()
83 }
84 }
85
86 function onStart() {
87 if (state.delayed) {
88 state.delayed = false
89 }
90
91 state.pauseQueue.delete(onPause)

Callers 2

flushUpdateFunction · 0.90
_updateMethod · 0.90

Calls 7

matchPropFunction · 0.90
callPropFunction · 0.90
onStartFunction · 0.85
onResumeFunction · 0.85
addMethod · 0.80
pauseMethod · 0.65
resumeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…