Skip to content

Commit

Permalink
Make all APIs chainable
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Miskiewicz committed Jan 16, 2018
1 parent c0fb41a commit b89559f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Spring {
* If `fromValue` differs from `toValue`, or `initialVelocity` is non-zero,
* start the simulation and call the `onStart` listeners.
*/
start() {
start(): Spring {
const { fromValue, toValue, initialVelocity } = this._config;

if (fromValue !== toValue || initialVelocity !== 0) {
Expand All @@ -87,14 +87,16 @@ export class Spring {
});
}
}

return this;
}

/**
* If a simulation is in progress, stop it and call the `onStop` listeners.
*/
stop() {
stop(): Spring {
if (!this._isAnimating) {
return;
return this;
}

this._isAnimating = false;
Expand All @@ -104,6 +106,8 @@ export class Spring {
cancelAnimationFrame(this._currentAnimationStep);
this._currentAnimationStep = 0;
}

return this;
}

/**
Expand Down Expand Up @@ -143,7 +147,7 @@ export class Spring {
* Updates the spring config with the given values. Values not explicitly
* supplied will be reused from the existing config.
*/
updateConfig(updatedConfig: PartialSpringConfig): void {
updateConfig(updatedConfig: PartialSpringConfig): Spring {
// When we update the spring config, we reset the simulation to ensure the
// spring always moves the full distance between `fromValue` and `toValue`.
// To ensure that the simulation behaves correctly if those values aren't
Expand All @@ -164,6 +168,8 @@ export class Spring {
};

this._reset();

return this;
}

/**
Expand Down

0 comments on commit b89559f

Please sign in to comment.