Skip to content

aninest / AnimatableEvents / addLocalListener

addLocalListener()

ts
function addLocalListener<Animating, Event>(
   anim, 
   type, 
   listener): 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

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

Defined in

Animate/AnimatableEvents.ts:58