Skip to content

Documentation / AnimatableEvents / addLocalListener

addLocalListener() ​

ts
function addLocalListener<Animating, Event>(
   anim, 
   type, 
   listener, 
   options): unsubscribe;

Defined in: Animate/AnimatableEvents.ts:101

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 ​

Animating extends Animatable<unknown>

Event ​

Event extends AnimatableEvents

Parameters ​

anim ​

Animation<Animating>

The animation object

type ​

Event

See AnimatableEvents

listener ​

Event extends | "beforeStart" | "immutableStart" | "start" | "end" | "interrupt" | "beforeEnd" ? Listener<Partial<SlicedAnimatable<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.

signal? ​

AbortSignal

Returns ​

unsubscribe

A function to remove the listener

Example ​

ts
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