Skip to content

Simplify Tween, remove some stuff, make it easier to maintain. #655

Description

@trusktr

Proposed (welcome to debate):

  • Ensure maximal ES Module support
  • remove legacy CommonJS after Electron ESM comes out
  • Remove the autostart parameter from tween.update(time, autostart). It makes the API less intuitive: for example if you call stop() and then the next animation frame calls update() and restarts the tween, it seems like stop() is not working. Better to make the APIs explicit: tweens will start and stop only when you tell them to, regardless if update is being called, and update does only one thing well (update the time).
    • This also allows us to eliminate confusion with onStart. Currently you call tween.start(), but onStart will be be fired until update() is called (f.e. in the next animation frame). Instead, we can make it be called immediately so that any state that should be initially set for the tween is guaranteed to be set, regardless of update().
  • Remove the TWEEN singleton, make Tweens start with no Group by default
    • docs: Teach people how to make a Tween and update it directly.
    • docs: Teach them that if they want to update multiple Tweens at once, they must make a Group.
    • This eliminates possible errors people will have when they clash tweens from two or more separate pieces of code (when using the current TWEEN)
    • explicitly managing each tween, or explicitly making Groups, will naturally lead to people writing componentized code with lowered chance of issues.
    • this leads to understanding of what is going on, rather than proper code being non-obvious up front
  • Remove relative values. It involves detecting strings for little convenience. People can just use math on their side with not much more effort.
  • Remove the dynamic-to feature. It isn't used often, and much internal complication.
  • Remove array of to-values, provide a replacement robust and decoupled Curve/Path API so we can animate along curves/paths (tracked in Curve/Path feature #721)
    • the array of to values adds quite some complexity muddied with the concept of a Tween and time animation.
    • When we use array of to values, we inadvertently destroy the meaning of an easing curve because the actual number output is no longer on that curve so the meaning is obscure.
    • the ability to choose interpolation method, f.e. bezier, which is useful for making a smooth curve out of the discrete points (f.e. "animate along a smooth path calculated from the discrete sharp values") is better in a separate more robust and flexible API, and we will simplify the job of Tween.
      • F.e. Three.js has Path and Curve tools
      • We can use a Tween to animate position along such path primitives.
  • Remove and replace .yoyo. Provide a reverse function that can return a new tween instance with reversed data.
    • Tween.yoyo is deprecated in feat!: Timeline orchestration (sequence/parallel, nesting, labels) #713, replaced with Timeline orchestration.
    • simplifies tween logic.
    • replaced with: timeline.add(tween).add(tween.reverse())
    • Perhaps instead of removing, tween.yoyo() can be a shortcut for tween.chain(tween.reverse()). The main idea is that the yoyo state is not intertwined inside the regular tween state like it currently is. Instead, two separate tweens each have their own state. Replaced with Timeline.
  • Replace tween.chain with a Timeline feature.
    • mark Tween.chain deprecated (done in feat!: Timeline orchestration (sequence/parallel, nesting, labels) #713, use a Timeline to sequence multiple Tweens)
    • This composes tweens independently of each other, so they don't need to have state remembering who they are chained to. This allows way more flexible new options (Timeline) like playing tweens in parallel, not just in sequence, etc.
  • improved testing.
    • run unit tests in browsers, because that's where Tween is used more often.
      • use @web/test-runner for this
    • Add a way to perform visual snapshot testing so that we may catch issues that unit tests may not, by snapshotting results of visual animations

What else?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions