sync
Creates a timer that completes on the next animation frame, useful for synchronizing operations with the animation engine’s tick cycle.Syntax
Parameters
Optional callback function that executes when the sync timer completes. Receives the Timer instance as an argument.
Returns
A Timer instance that completes after one frame, respecting the global time scale.
Examples
Use Cases
Frame Sync
Synchronize operations with the animation engine’s frame updates
Timing Coordination
Coordinate multiple animations or operations on the same frame
keepTime
A higher-order function that wraps an animation constructor to preserve its time state (iteration, progress, direction) across function calls. This is particularly useful in reactive frameworks where components re-render frequently.Syntax
Parameters
A function that creates and returns an animation or tickable object. The function should return either:
- A tickable object (with
.revert()method) like an animation instance - A cleanup function
- Nothing (void)
Returns
A wrapped version of the constructor that preserves animation time state between calls.
How It Works
-
When the wrapped function is called, it captures the current state of any previous animation:
- Current iteration number
- Progress within the current iteration
- Play direction (forward/reversed)
- Alternate state
- It reverts the previous animation (if any)
- It creates a new animation by calling the original constructor
- It restores the captured state to the new animation
- Returns the cleanup function or animation instance
Examples
Basic Usage
With React (Preserving State on Re-render)
With Vue (Preserving State on Updates)
Without keepTime (State Lost)
With keepTime (State Preserved)
When to Use These Utilities
sync()
sync()
Use
sync() when you need to:- Execute code on the next animation frame
- Synchronize operations with the animation engine
- Ensure timing consistency with other animations
- Respect the global time scale setting
keepTime()
keepTime()
Use
keepTime() when you:- Work with reactive frameworks (React, Vue, Svelte, etc.)
- Need to update animation parameters without restarting
- Want to preserve loop iterations and progress
- Have dynamic animations that respond to state changes
- Need smooth transitions when props/state update
Benefits of keepTime
Seamless Updates
Update animation parameters without jarring restarts or position jumps
State Preservation
Maintain loop count, progress, and direction across re-renders
Framework Friendly
Works naturally with React, Vue, Svelte, and other reactive frameworks
Smooth UX
Create fluid, uninterrupted animations even with dynamic content
Technical Details
sync() creates a Timer with duration of 1 * globals.timeScale, ensuring it completes on the next frame while respecting any global time scaling.keepTime() captures four key state properties: currentIteration, iterationProgress, reversed, and _alternate. These are restored to the new animation instance to maintain continuity.