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
Feature - deep $watch #2462
Feature - deep $watch #2462
Conversation
What's the performance impact of using |
I would expect we'll need a very huge dataset to make an appreciable difference and at that point, Alpine itself would have issue because it needs to crawl the same number of nodes to convert them to proxies. But it's a good argument for making it optional. For real arrays, we are already crawling all elements to convert them to strings to be fair. |
Yeah, I'd personally opt for the Vue-like API with the |
https://codepen.io/SimoTod/pen/jOGqzBB this uses the current implementation |
Nice, thanks for the benchmark Simone. Yeah, in this case then, I'd just always have deep watching enabled. |
I like this as the default, thanks for checking on those things @ryangjchandler and @SimoTod - and thanks for actually benchmarking the difference @SimoTod - great addition! |
You could test for structuredClone and use it where available (just FF at the moment). |
This PR enables deep watching by default. JSON.stringify(value) will touch any single property (or element for arrays) so they'll get picked up by the reactivity framework.
Pending questions before merging:
VueJs doesn't offer it by default but it has a deep flag. To me, it makes more sense to just make it deep by default which is what most of the users asked for, I think. However, I'm happy to introduce the flag if we think it's better, either defaulted to false like VueJs or to true.
If the watcher changes a different property on the same object, it will trigger an infinite loop, should we introduce a control variable to pause the watcher during the change?