The fundamental problem here is how do you handle updating the current time.
It’s not entirely clear in the post, but it sounds like you are looking at mdgriffith/elm-style-animation. I will also consider my own library, mgold/elm-animation. I actually recommend mdgriffith’s library for most cases since it handles animating styles rather than Float values, but let’s get back to updating the current time.
In elm-style-animation, you
- Subscribe to an opaque animation message (but it’s just the current time) by passing a library function a list of all your animations,
- Update every animation on every frame to contain the current time, and
- Render and interrupt without passing the current time.
You shouldn’t be dynamically (i.e. at runtime) adding or removing the animation subscription, or animations passed to generate it, because it will automatically stop sending events if no animations are running. The brittleness of this model instead comes from adding a new animation to the model, since you also have to add it to the update and subscription functions for it to work.
The other issue with this approach is that you compute and allocate new animation records on every frame. I would imagine that this has performance implications, but apparently it hasn’t been a problem. The APIs for render and interrupt are simplified.
In elm-animation, you
- Subscribe constantly to the time delta provided by AnimationFrame,
- Update the current time in the model by adding the delta, and
- Render and interrupt by passing the current time.
This setup eliminates the brittle subscribe and update functions, and requires only a constant change (vs. the number of animations) to the model each frame. The APIs for render and interrupt require an extra parameter, the current time.
In elm-animation, you can query for the value of an animation at any time because it’s computed as a mathematical easing function. In elm-style-animation, as I understand it, there are simulations involving springs that require updates each frame. The physics simulation requires the “new frame, new animation” approach to work well. So I take it that’s why it’s done that way.