UNPKG

react-spring

Version:
60 lines (52 loc) 1.26 kB
import AnimatedValue from '../../animated/AnimatedValue' export function shallowEqual(a, b) { for (let i in a) if (!(i in b)) return false for (let i in b) if (a[i] !== b[i]) return false return true } export function callProp(arg, state) { return typeof arg === 'function' ? arg(state) : arg } export function getValues(object) { return Object.keys(object).map(k => object[k]) } export function getForwardProps(props) { const { to, from, config, native, onRest, onFrame, children, render, reset, force, immediate, impl, inject, delay, attach, ...forward } = props return forward } export function renderChildren(props, componentProps) { const forward = { ...componentProps, ...getForwardProps(props) } return props.render ? props.render({ ...forward, children: props.children }) : props.children(forward) } export function convertToAnimatedValue(acc, [name, value]) { return { ...acc, [name]: new AnimatedValue(value), } } export function convertValues(props) { const { from, to, native } = props const allProps = Object.entries({ ...from, ...to }) return native ? allProps.reduce(convertToAnimatedValue, {}) : { ...from, ...to } }