Add modifier defer
to control deferring storage
#3463
Closed
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.
The persist plugin right now stores the value immediately on initialization. This prevents me from being able to use it in quite a few cases, where nothing should be stored in the browser before user interaction (GDPR compliance).
This PR attempts to solve this problem by adding a new modifier
$persist('my-value').defer()
that will wait for the first mutation of the data before storing it in the browser.In my (manual) tests, it's already working fine for primitives, but for arrays and objects there seems to be something I'm missing (cypress tests are failing for arrays/objects right now).
If anyone from the maintainers thinks this could be a useful feature, I would be very grateful if they could have a look at why this fails with arrays. (Something inside
Alpine.effect()
, I guess...)Actually, I'll add a failing test for arrays, so that it's easier for you guys.