|
1 | | -import { FluidValue } from "./fluids" |
2 | | -import { FrameValue } from "./FrameValue" |
3 | | -import { Any } from "./utils" |
| 1 | +import * as G from './globals' |
| 2 | +import { getAnimated, getPayload, setAnimated } from "./animated" |
| 3 | +import { createInterpolator } from "./createInterpolator" |
| 4 | +import { addFluidObserver, callFluidObservers, FluidValue, getFluidValue, hasFluidValue, removeFluidObserver } from "./fluids" |
| 5 | +import { frameLoop } from "./FrameLoop" |
| 6 | +import { FrameValue, isFrameValue } from "./FrameValue" |
| 7 | +import { raf } from "./rafz" |
| 8 | +import { Any, toArray, each, getAnimatedType, isEqual, is } from "./utils" |
4 | 9 |
|
5 | 10 | export type Animatable<T = any> = T extends number |
6 | 11 | ? number |
@@ -245,3 +250,32 @@ export interface InterpolatorFactory { |
245 | 250 |
|
246 | 251 | <In, Out>(...args: InterpolatorArgs<In, Out>): InterpolatorFn<In, Out> |
247 | 252 | } |
| 253 | + |
| 254 | + |
| 255 | +/** Returns true for an idle source. */ |
| 256 | +function isIdle(source: any) { |
| 257 | + return source.idle !== false |
| 258 | +} |
| 259 | + |
| 260 | +/** Return true if all values in the given set are idle or paused. */ |
| 261 | +function checkIdle(active: Set<FluidValue>) { |
| 262 | + // Parents can be active even when paused, so the `.every` check |
| 263 | + // removes us from the frameloop if all active parents are paused. |
| 264 | + return !active.size || Array.from(active).every(isIdle) |
| 265 | +} |
| 266 | + |
| 267 | +/** Become idle if not already idle. */ |
| 268 | +function becomeIdle(self: Interpolation) { |
| 269 | + if (!self.idle) { |
| 270 | + self.idle = true |
| 271 | + |
| 272 | + each(getPayload(self)!, node => { |
| 273 | + node.done = true |
| 274 | + }) |
| 275 | + |
| 276 | + callFluidObservers(self, { |
| 277 | + type: 'idle', |
| 278 | + parent: self, |
| 279 | + }) |
| 280 | + } |
| 281 | +} |
0 commit comments