phetsims / twixt

Animation library for interactive HTML5 graphics
MIT License
1 stars 3 forks source link

help needed with Animation config.to #25

Closed pixelzoom closed 5 years ago

pixelzoom commented 5 years ago

Animation uses the config pattern, and it's documentation says:

  If there is only one target, it is recommended to pass in those config in the top-level Animation config, e.g.:
   * | var someNumberProperty = new NumberProperty( 0 );
   * | new Animation( {
   * |   // Options for the Animation as a whole
   * |   duration: 2,
   * |
   * |   // Options for the one target to change
   * |   property: someNumberProperty,
   * |   to: 5
   * | } );
   *
...
  @param {Object} config - See below in the constructor for documentation.

After having to look through the entire source code for config fields (which is what I really despise about the config pattern in general), I can find no reference to config.to anywhere in Animation.

@jonathanolson can you please point me to where config.to is documented in Animation?

pixelzoom commented 5 years ago

Answered my own question.

    // @private {Array.<AnimationTarget>} - All of the different values that will be animated by this animation.
    // If config.targets was supplied, those targets will be wrapped into AnimationTargets
    // If config.targets was not supplied, the config from this object will be wrapped into one AnimationTarget
    this.targets = _.map( config.targets === null ? [ config ] : config.targets, function( config ) {
      return new AnimationTarget( config ); // TODO #3: strip out the irrelevant config when using config arg
    } );

So I guess that all AnimationTarget config fields are fair game to put directly into Animation config. Seems like a big price to pay for that convenience.