You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new Spring class is great, and in particular the fact that Spring.of() can be used in conjuction with spring.set() is super useful.
However, after using .set(), the spring stays at the provided value until reactivity causes its initial function to be reevaluated. This is expected and not a problem at all, but it's just undesirable in some cases, so I was wondering if DX could be improved a bit.
Consider something like:
// a, b, c and d change rarelyleta=$state(2);letb=$state(4);letc=$state(8);letd=$state(16);constspring=Spring.of(()=>a*b*c*d);functionsetSpringValue(x){spring.set(x);}
The spring will remain at the value passed as x until either a, b, c or d change, which could take a long time (or could happen literally immediately, making the whole thing a bit useless).
If we want the spring to go back to a * b * c * d after reaching x, one way to do it is:
Again, this is fine, but can just turn into a lot of boilerplate in real-world situations with lots of spring-based UIs.
Describe the proposed solution
To go along with the set() feature, it would be nice to have a way to force a reevaluation of the function initially provided to the Spring.
Something like spring.reset() could make things a little cleaner imo, instructing the spring to re-run its initial function without having to create a $derived.
- let calculatedTarget = $derived(a * b * c * d);- const spring = Spring.of(() => calculatedTarget);- function setSpringValue(x) {- spring.set(x).then(() => spring.set(calculatedTarget);- }+ const spring = Spring.of(() => a * b * c * d);+ function setSpringValue(x) {+ spring.set(x).then(() => spring.reset();+ }
And additionally, maybe an option could be passed to .set(), to make this process even easier?
// default behavior:spring.set(x,{reevaluate: 'reactive'});// stop responding to reactivity until `x` is reached, then reevaluate the initial fnspring.set(x,{reevaluate: 'after'});// responds to reactivity throughout animation towards `x` as usual, and upon reaching `x` reevaluate the initial fnspring.set(x,{reevaluate: 'reactiveAfter'});// stops reactivity entirely until manually re-enabled with spring.reset()spring.set(x,{reevaluate: 'never'});
Conversely, this would also allow for more control in situations where a, b, c and d change a lot, and we just want the spring to chill for a bit.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered:
Describe the problem
The new Spring class is great, and in particular the fact that
Spring.of()
can be used in conjuction withspring.set()
is super useful.However, after using
.set()
, the spring stays at the provided value until reactivity causes its initial function to be reevaluated. This is expected and not a problem at all, but it's just undesirable in some cases, so I was wondering if DX could be improved a bit.Consider something like:
The spring will remain at the value passed as
x
until eithera
,b
,c
ord
change, which could take a long time (or could happen literally immediately, making the whole thing a bit useless).If we want the spring to go back to
a * b * c * d
after reachingx
, one way to do it is:Again, this is fine, but can just turn into a lot of boilerplate in real-world situations with lots of spring-based UIs.
Describe the proposed solution
To go along with the
set()
feature, it would be nice to have a way to force a reevaluation of the function initially provided to the Spring.Something like
spring.reset()
could make things a little cleaner imo, instructing the spring to re-run its initial function without having to create a$derived
.And additionally, maybe an option could be passed to
.set()
, to make this process even easier?Conversely, this would also allow for more control in situations where
a
,b
,c
andd
change a lot, and we just want the spring to chill for a bit.Importance
would make my life easier
The text was updated successfully, but these errors were encountered: