aninest root / AnimatableEvents / addLocalListener
addLocalListener()
function addLocalListener<Animating, Event>(
anim,
type,
listener,
options): unsubscribe
Adds a local listener to the animation. You can listen to the events listed in AnimatableEvents. Animation listeners are scoped to only trigger when the current level of the animation is modified. Animation listeners are called in the order in which they were added.
Type Parameters
• Animating extends RecursiveAnimatable
<unknown
>
• Event extends AnimatableEvents
Parameters
• anim: Animation
<Animating
>
The animation object
• type: Event
See AnimatableEvents
• listener: Event
extends | "beforeStart"
| "start"
| "end"
| "interrupt"
| "beforeEnd"
? Listener
<Partial
<LocalAnimatable
<Animating
>>> : Listener
<undefined
>
The listener function - return true from the function to remove the listener
• options = {}
Contains one option, signal
which supports passing in an AbortSignal.
• options.signal?: AbortSignal
Returns
A function to remove the listener
Example
const anim = createAnimation({ a: newVec2(0, 0), b: newVec(0, 0) }, getLinearInterp(1))
addLocalListener(anim, "start", state => console.log("started", state)) // will never get triggered no matter what
addLocalListener(anim.children.a, "start", state => console.log("started", state)) // will trigger
modifyTo(anim, {a: {x: 1}}) // will trigger the listener on the 'a' child
See
addRecursiveListener for a recursive listener which triggers on any child modification