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

Function SpringRef

packages/core/src/SpringRef.ts:79–184  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

77}
78
79export const SpringRef = <
80 State extends Lookup = Lookup,
81>(): SpringRef<State> => {
82 const current: Controller<State>[] = []
83
84 const SpringRef: SpringRef<State> = function (props) {
85 deprecateDirectCall()
86
87 const results: AsyncResult[] = []
88
89 each(current, (ctrl, i) => {
90 if (is.und(props)) {
91 results.push(ctrl.start())
92 } else {
93 const update = _getProps(props, ctrl, i)
94 if (update) {
95 results.push(ctrl.start(update))
96 }
97 }
98 })
99
100 return results
101 }
102
103 SpringRef.current = current
104
105 /** Add a controller to this ref */
106 SpringRef.add = function (ctrl: Controller<State>) {
107 if (!current.includes(ctrl)) {
108 current.push(ctrl)
109 }
110 }
111
112 /** Remove a controller from this ref */
113 SpringRef.delete = function (ctrl: Controller<State>) {
114 const i = current.indexOf(ctrl)
115 if (~i) current.splice(i, 1)
116 }
117
118 /** Pause all animations. */
119 SpringRef.pause = function () {
120 each(current, ctrl => ctrl.pause(...arguments))
121 return this
122 }
123
124 /** Resume all animations. */
125 SpringRef.resume = function () {
126 each(current, ctrl => ctrl.resume(...arguments))
127 return this
128 }
129
130 /** Update the state of each controller without animating. */
131 SpringRef.set = function (
132 values:
133 | Partial<State>
134 | ((i: number, ctrl: Controller<State>) => Partial<State>)
135 ) {
136 each(current, (ctrl, i) => {

Callers 5

initSpringRefFunction · 0.90
useSpringsFunction · 0.90
useSpring.test.tsxFile · 0.90
useTransitionFunction · 0.90

Calls 10

deprecateDirectCallFunction · 0.90
eachFunction · 0.90
_getPropsFunction · 0.85
_getPropsMethod · 0.80
startMethod · 0.65
pauseMethod · 0.65
resumeMethod · 0.65
setMethod · 0.65
stopMethod · 0.65
updateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…