Download react-spring/packages/animated/src/AnimatedObject.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedObject.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedObject.ts
-
curl -L -o AnimatedObject.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedObject.ts
1.63 kB
| import { Lookup } from '@react-spring/types' | |
| import { | |
| each, | |
| eachProp, | |
| getFluidValue, | |
| hasFluidValue, | |
| } from '@react-spring/shared' | |
| import { Animated, isAnimated, getPayload } from './Animated' | |
| import { AnimatedValue } from './AnimatedValue' | |
| import { TreeContext } from './context' | |
| /** An object containing `Animated` nodes */ | |
| export class AnimatedObject extends Animated { | |
| constructor(protected source: Lookup) { | |
| super() | |
| this.setValue(source) | |
| } | |
| getValue(animated?: boolean) { | |
| const values: Lookup = {} | |
| eachProp(this.source, (source, key) => { | |
| if (isAnimated(source)) { | |
| values[key] = source.getValue(animated) | |
| } else if (hasFluidValue(source)) { | |
| values[key] = getFluidValue(source) | |
| } else if (!animated) { | |
| values[key] = source | |
| } | |
| }) | |
| return values | |
| } | |
| /** Replace the raw object data */ | |
| setValue(source: Lookup) { | |
| this.source = source | |
| this.payload = this._makePayload(source) | |
| } | |
| reset() { | |
| if (this.payload) { | |
| each(this.payload, node => node.reset()) | |
| } | |
| } | |
| /** Create a payload set. */ | |
| protected _makePayload(source: Lookup) { | |
| if (source) { | |
| const payload = new Set<AnimatedValue>() | |
| eachProp(source, this._addToPayload, payload) | |
| return Array.from(payload) | |
| } | |
| } | |
| /** Add to a payload set. */ | |
| protected _addToPayload(this: Set<AnimatedValue>, source: any) { | |
| if (TreeContext.dependencies && hasFluidValue(source)) { | |
| TreeContext.dependencies.add(source) | |
| } | |
| const payload = getPayload(source) | |
| if (payload) { | |
| each(payload, node => this.add(node)) | |
| } | |
| } | |
| } | |