Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a
Spring
class as an alternative to the existingspring
store factory. The behaviour is essentially identical, but the API is slightly different:instant
andpreserveMomentum
are clearer thanhard
andsoft
, which seem like they're somehow symmetrical but are in fact unrelated.As an alternative to providing an initial value, you can provide a function, making it easy to keep a spring in sync with some other value:
In this case it's still possible to do
thing.set(value, opts)
, since you might (e.g.) need to use{ instant: true }
, and making it 'readonly' in the function case could be overly restrictive.Initially I envisaged that there'd be a
spring.target
property, and you'd update the spring by updating that value. But reading through #2627 made me realise that there are many cases where you need programmatic control (e.g. gesture-based interactions) so we need aspring.set(...)
method, and having two ways to do the same thing could be confusing.That said, it might be nice to be able to do this sort of thing...
...and so the possibility is left open.
A nice thing about using classes: you can do
const spring = new Spring(...)
instead of always having to come up with a more descriptive name.TODO
Tween
class to go withSpring
spring
tests to adapt — not totally sure what tests would look like here)Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint