Controller

A Controller maintains state for an arbitrary set of properties.

When a controller is created, all properties passed into its constructor will be stored in state.

PropertyTypeDescription
stateobjectThe controller's current state.
connectedanyAny data stored using the connect method.
animationAnimeInstanceAny data stored using the connect method.
isAnimatingWhether the controller's current animation is animating.
MethodDescription
setState(state)Merges the provided values into the controller's state.
animate(options, path?)Animate the controller's state. Uses animejs. If animating an object property, use the key of the object property as the second parameter. (e.g. If animating the top property of controller.state.something, use controller.animate({top: 100}, 'something').) Returns an anime instance that can be paused and resumed.
connect(data)Stores the provided data as the controller's connected property.
reset()Resets the controller to its initial state.
stopAnimation()Stop any current animation.
pauseAnimation()Pause any current animation.
resumeAnimation()Resume any current animation.

In addition, the Controller class has three protected life cycle methods. If you're writing a class that extends Controller, you can overwrite these methods in your class.

Protected MethodDescription
onUpdate(state: State, connected: any)A lifecycle method fired when the controller's state updates.
onConnect(state: State, connected: any)A lifecycle method fired when the controller connects to data.
onReset(state: State, connected: any)A lifecycle method fired when the controller resets its state.

Example: