Skip to content

Commit 49b6b37

Browse files
committed
feat: export "inferTo" function
and the InferTo type.
1 parent 2c71369 commit 49b6b37

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

packages/core/src/Controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import { Indexable, Falsy } from './types/common'
2222
import { runAsync, scheduleProps, RunAsyncState, AsyncResult } from './runAsync'
2323
import { SpringPhase, CREATED, ACTIVE, IDLE } from './SpringPhase'
24-
import { interpolateTo } from './helpers'
24+
import { inferTo } from './helpers'
2525
import { SpringValue } from './SpringValue'
2626
import { FrameValue } from './FrameValue'
2727

@@ -103,7 +103,7 @@ export class Controller<State extends Indexable = UnknownProps>
103103
constructor(props?: ControllerProps<State>) {
104104
this._onFrame = this._onFrame.bind(this)
105105
if (props) {
106-
const { to, ...initialProps } = interpolateTo(props as any)
106+
const { to, ...initialProps } = inferTo(props as any)
107107
this._initialProps = initialProps
108108
if (to) this.start({ to })
109109
}
@@ -261,7 +261,7 @@ export class Controller<State extends Indexable = UnknownProps>
261261

262262
/** Prepare an update with the given props. */
263263
protected _prepareUpdate(propsArg: ControllerProps<State>) {
264-
const props: PendingProps<State> = interpolateTo(propsArg) as any
264+
const props: PendingProps<State> = inferTo(propsArg) as any
265265
let { from, to } = props as any
266266

267267
// Avoid sending async "to" prop to springs.

packages/core/src/helpers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { interpolateTo } from './helpers'
1+
import { inferTo } from './helpers'
22
import { ReservedProps } from './types/common'
33

44
describe('helpers', () => {
@@ -38,7 +38,7 @@ describe('helpers', () => {
3838
onRest: undefined,
3939
}
4040
expect(
41-
interpolateTo({
41+
inferTo({
4242
...forwardProps,
4343
...restProps,
4444
...excludeProps,

packages/core/src/helpers.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,19 @@ function getForwardProps<Props extends ReservedProps>(
108108
return forward
109109
}
110110

111-
export type InterpolateTo<T extends object> = Merge<
111+
/**
112+
* Move all non-reserved props into the `to` prop.
113+
*/
114+
export type InferTo<T extends object> = Merge<
112115
{ to: ForwardProps<T> },
113116
Pick<T, keyof T & keyof ReservedProps>
114117
>
115118

116-
export function interpolateTo<T extends object>(props: T): InterpolateTo<T> {
119+
/**
120+
* Clone the given `props` and move all non-reserved props
121+
* into the `to` prop.
122+
*/
123+
export function inferTo<T extends object>(props: T): InferTo<T> {
117124
const to = getForwardProps(props)
118125
const out: any = { to }
119126
each(props, (val, key) => key in to || (out[key] = val))

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export {
3636
UnknownProps,
3737
} from './types/common'
3838

39+
export { inferTo, InferTo } from './helpers'
3940
export { FrameLoop, Animatable, createInterpolator } from 'shared'
4041

4142
export * from 'shared/types/animated'

packages/core/src/useTransition.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from 'shared'
2020
import { now } from 'shared/globals'
2121

22-
import { DEFAULT_PROPS, callProp, interpolateTo } from './helpers'
22+
import { DEFAULT_PROPS, callProp, inferTo } from './helpers'
2323
import { SpringHandle, AsyncTo, FromProp, SpringValues } from './types/spring'
2424
import { Controller, ControllerProps } from './Controller'
2525
import { AnimationProps, AnimationEvents } from './types/animated'
@@ -244,7 +244,7 @@ export function useTransition(
244244
from: callProp(from, t.item, i),
245245
delay: delay += trail,
246246
config: callProp(props.config || defaultProps.config, t.item, i),
247-
...(is.obj(to) && interpolateTo(to)),
247+
...(is.obj(to) && inferTo(to)),
248248
}
249249

250250
const { onRest } = payload

0 commit comments

Comments
 (0)