Skip to content

Conversation

@TomFevrier
Copy link

When tweening arrays of objects, boolean properties can be useful (e.g. for toggling classes), and it makes no sense (in my opinion) to prevent developers from using boolean values in tweened stores.

This simple fix simply updates any boolean value without trying to interpolate it or throwing a Cannot interpolate boolean values error.

See issue: #7543

@vercel
Copy link

vercel bot commented May 31, 2023

@TomFevrier is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@gtm-nayan
Copy link
Contributor

gtm-nayan commented Jun 8, 2023

I don't think this is a good idea. We really shouldn't be interpolating between non-numeric values. What if someone expects the boolean to flip halfway through instead of immediately or at the end? How is it affected by easing?

You can pass a custom interpolator with the exact behaviour that you desire.

@TomFevrier
Copy link
Author

TomFevrier commented Jun 8, 2023

I don't think this is a good idea. We really shouldn't be interpolating between non-numeric values. What if someone expects the boolean to flip halfway through instead of immediately or at the end? How is it affected by easing?

You can pass a custom interpolator with the exact behaviour that you desire.

Why would anyone expect anything, since Svelte currently doesn't allow it? How could it be affected by easing, since a boolean cannot be interpolated anyway?

In my opinion, it makes sense that the boolean would flip immediately, since this boolean would mostly be used:

  • either as a class: directive to trigger a CSS transition
  • or in the condition of an {#if}...{/if} block, to mount content conditionally and animate it using a transition: directive
    In both cases, the delay and duration of the transition triggered by the boolean can be customized.

I admit this is a very niche case, but as a visual journalist, I've encountered this problem a few times while using tweened to animate graphics and datavisualizations. Of course, one can always use a custom interpolator, but it's quite painful to copy the entire get_interpolator function from the Svelte source code simply to add one line to make it work with booleans. For a common usage of Svelte, I don't see how it would cause any issue and I think the benefits outweigh the drawbacks, if any.

@vercel
Copy link

vercel bot commented Jun 22, 2023

Deployment failed with the following error:

There is no GitHub account connected to this Vercel account.

@Rich-Harris
Copy link
Member

I think we can go further and snap all non-numeric values to their final destination. Closing this in favour of #14941

@Rich-Harris Rich-Harris closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants