Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As highlighted by #83, there are still performance issues with the proxy.
When a proxy is created, even if it's not directly assigned to a variable, it stays in memory and it keeps observing the variable. When accessing multiple time the same variable, the proxyHandler creates a new proxy object every time and they remain active after the initial use.
It means then, if we read 10 time a property containing an object, there will be 10 proxy watching the variable which will trigger 10 refreshed every time it changes.
Proposed new approach: rather than creating a new proxy every time we access a nested variable, we create a deep proxy at the beginning so we don't proxy only the first level but we do recursively for all level (objects would generate a proxies as soon as a directive use them any way so resource wise it's pretty much the same). The get trap just return true if property is '$isAlpineProxy' otherwise it returns the property value: we don't create new proxy here so it should resolve both the issues where proxy were nested or duplicated.
The set trap, when we add a new object, will try to create a deep proxy before inserting it to keep the property reactive.
The deepProxy utility will just create a proxy for valid objects and will ignore null values, DomNodes, existing proxies, etc.
I tried myself and I saw performance improvements, old tests still pass and examples looks okay.
I've asked one of the user to stress test it as well.
I'm conscious that it touches a low-level part of the core so I understand if you want to take a bit of time to test it or you want to changes/improves anything.
Hopefully it should fix all this proxy drama. :)