Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immediate tweened store value update with { duration: 0 } option #4399

Closed
Yxwww opened this issue Feb 10, 2020 · 5 comments · Fixed by #4766
Closed

Immediate tweened store value update with { duration: 0 } option #4399

Yxwww opened this issue Feb 10, 2020 · 5 comments · Fixed by #4766

Comments

@Yxwww
Copy link

Yxwww commented Feb 10, 2020

Is your feature request related to a problem? Please describe.
In Firefox and Safari, when there's a tweened store and we call tweenedStore.update(fn, {duration: 0}) sometimes the tweened value gets computed to NaN. Then I went to read about how the value gets computed:
https://github.com/sveltejs/svelte/blob/master/src/runtime/motion/tweened.ts#L121
As the result is based on elapsed/duration, which makes sense to not have duration to be 0 mathematically. Although, in FF and Safari the elapsed variable can be 0 when compute is getting executed, which causes the result of the compute to be NaN.

Describe the solution you'd like
if the options.duration is 0 then we set the value right away instead of going through the interpolation compute ?

Describe alternatives you've considered

  • We can clamp the lower bound duration to 1, just in case another person runs into situation like this
  • error on passing options.duration when <=0

How important is this feature to you?
Currently I'm using {duration: 1} as a work around. when I want to update some tweened store "immediately". I'm curious about what would be a good way to handle this tho !

Additional context
Thanks for reading !

@tivac
Copy link
Contributor

tivac commented Feb 11, 2020

I'd prefer to early-out and immediately set the value in this case as well.

@arggh
Copy link
Contributor

arggh commented Apr 2, 2020

I bumped into this issue while implementing touch gestures for an image gallery. I wanted to set the value immediately when handling touch events, but have the possibility to tween/spring the values when, for example, the user's gesture moved something a bit too far and I need to revert state to the nearest sensible value.

tivac added a commit to tivac/svelte that referenced this issue May 3, 2020
@Conduitry
Copy link
Member

This has been implemented in 3.22.0.

@tivac
Copy link
Contributor

tivac commented May 3, 2020

Thanks for the quick merge and release @Conduitry!

@Yxwww
Copy link
Author

Yxwww commented May 4, 2020

Thanks !

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

Successfully merging a pull request may close this issue.

4 participants