Download react-spring/packages/animated/src/AnimatedArray.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedArray.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedArray.ts
-
curl -L -o AnimatedArray.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedArray.ts
1.19 kB
| import { isAnimatedString } from '@react-spring/shared' | |
| import { AnimatedObject } from './AnimatedObject' | |
| import { AnimatedString } from './AnimatedString' | |
| import { AnimatedValue } from './AnimatedValue' | |
| type Value = number | string | |
| type Source = AnimatedValue<Value>[] | |
| /** An array of animated nodes */ | |
| export class AnimatedArray< | |
| T extends ReadonlyArray<Value> = Value[], | |
| > extends AnimatedObject { | |
| declare protected source: Source | |
| constructor(source: T) { | |
| super(source) | |
| } | |
| /** @internal */ | |
| static create<T extends ReadonlyArray<Value>>(source: T) { | |
| return new AnimatedArray(source) | |
| } | |
| getValue(): T { | |
| return this.source.map(node => node.getValue()) as any | |
| } | |
| setValue(source: T) { | |
| const payload = this.getPayload() | |
| // Reuse the payload when lengths are equal. | |
| if (source.length == payload.length) { | |
| return payload.map((node, i) => node.setValue(source[i])).some(Boolean) | |
| } | |
| // Remake the payload when length changes. | |
| super.setValue(source.map(makeAnimated)) | |
| return true | |
| } | |
| } | |
| function makeAnimated(value: any) { | |
| const nodeType = isAnimatedString(value) ? AnimatedString : AnimatedValue | |
| return nodeType.create(value) | |
| } | |