Reactive Collections Syntax in ripple files #393
Replies: 6 comments 8 replies
-
|
We considered this but it's too magical and also not very explicit. The type system will not know that these arrays etc are actually tracked arrays, and there's no way to make TS do that – we tried when making Svelte 5. Under the hood they're proxied objects and that means people lose out on knowing if an object is tracked or not – to be able to know when something can be reactive. Another reason is that sometimes you just want to track an array and not have it tracked. This is what we do in the JS framework benchmark, because creating a fully tracked array is wasteful if you don't need it be fully tracked. |
Beta Was this translation helpful? Give feedback.
-
|
And to expand, excluding the inability to TS type things. Vue went for deep reactivity as their default, just like Svelte. And similarly they're using proxies. Ripple also uses proxy's for arrays and objects but only with shallow reactivity as the default. So, in their case for non-primitive values, all nested objects require their own Proxy and each proxy slows things down. We discussed this several times and strongly felt that deep reactivity as the default is usually a huge overkill and may lead to significant performance issues. Like the ole saying goes, "If all you have is a hammer, everything looks like a nail". In real life, it's not that often that you want everything to be reactive. So, Ripple gives you full control of how to define your reactivity. Ripple provides the primitives, and, if needed, people can make things deeply reactive. Since they're in control, they know exactly (they should at least) what they're doing so they can find issues and bottlenecks and fix them much more easily. This also allows Ripple to separate reactivity of the variable itself from its contents, which provides additional flexibility in structuring your code as well as better performance for many use cases to avoid much more expensive reactivity cascading effects. Bottom line, reactivity is not free. And when everything is reactive, it really can add up to not such a great experience for either developers or users. |
Beta Was this translation helpful? Give feedback.
-
|
If I understand this correctly So On the other hand We can then mix and match these two concepts together depending on our use-case (aka. do I want to track re-assignment and/or content change?). I understand and generally like shorthand syntaxes although it does increase the learning curve and/or confusion. Ultimatelly the choice is between verbosity and simplicity which I think would be OK if all complex values had both the verbose and simple syntax. What I don't like is that I'll have to write and read code like this: I would much better do this: Or something like this: |
Beta Was this translation helpful? Give feedback.
-
|
We could definitely do that, but it would be confusing too why someone couldn't do |
Beta Was this translation helpful? Give feedback.
-
|
We shipped this today, so closing. |
Beta Was this translation helpful? Give feedback.
-
|
We also have new #Date #URL #URLSearchParams |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Ripple community, I'm joining the party slightly late, and I love what I'm seeing so far.
There are a few things that I would like to propose, regarding the syntax for collections currently .
Here's the current syntax to declare a reactive collection :
(There's also TrackedDate, but dates aren't collections)
As someone coming from vue where you can use ref with these 4 things, I can't help but feeling that this is a downgrade.
Is there a good reason to not re-use the neat track/@ here ?
I feel like this is the best of both worlds, as
@is more succint than.value, but it still clearly delimits what is reactive and what isn't.The tradeoff is that the
@syntax obviously only works in.ripplefiles.But maybe something like
useTrackcould be introduced to usetrackin plain js/ts files?PS: I've read that under the hood ripple isn't using signals. So maybe
track([])could be sugar forTrackArray.from([])Beta Was this translation helpful? Give feedback.
All reactions