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
This PR was developed when I started having problems trying to reset a syncedCrud observable with syncState.reset().
fix syncState.reset() not updating observable's value when the initial value of a synced observable is an empty object
fix syncState.reset() not updating observable's value when called multiple times (I had this issue in an Expo to-dos test page, where I set up a synced observable and added one to-do, then reset, then added one to-do again, then reset again. On the second reset, the observable's value didn't update)
fix syncState.isLoaded not being set correctly when resetting a synced observable that didn't have the get property (e.g. syncedCrud with list property)
Your fix has one problem. It clones the value to reset to and thus reset will throw if json.parse or json.stringify used by clone throw.
legend-state adds Date, Map and Set serialization on top of what JSON.stringify does. Anything else in the reset value will make reset throw. On top of what you already did in your fix, we could run available transforms on the reset value to avoid this.
A much easier and faster solution would be to not have a reset value in the syncedOptions but a function returning the reset value. Docs would have to state that the function returning the reset value should not return the same reference.
initial already is typed (() => T) | T | undefined. So we can just remove the T option and set the obs to the value returned by the function passed to initial or undefined.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This PR was developed when I started having problems trying to reset a
syncedCrudobservable withsyncState.reset().syncState.reset()not updating observable's value when the initial value of a synced observable is an empty objectsyncState.reset()not updating observable's value when called multiple times (I had this issue in an Expo to-dos test page, where I set up a synced observable and added one to-do, then reset, then added one to-do again, then reset again. On the second reset, the observable's value didn't update)syncState.isLoadednot being set correctly when resetting a synced observable that didn't have thegetproperty (e.g.syncedCrudwithlistproperty)