react-native-onyx
react-native-onyx copied to clipboard
`Onyx.clear()` will wipe `Onyx.set()` from `Storage`
cc @neil-marcellini and coming from https://github.com/Expensify/react-native-onyx/pull/129#discussion_r883005645...
Unsure if there is any observable problem with this at the moment, but it just doesn't seem like the expected behavior.
This is how this code runs today...
const promises = [];
promises.push(Onyx.clear());
promises.push(Onyx.set('test', {someValue: 'test'});
Promise.all(promises)
.then(() => {
Storage.getItem('test').then((val) => console.log(val)) // null
});
The cache values end up correct, but the storage values are not. The behavior is documented but we might want to fix it eventually.
One idea I had:
- Set an internal flag that
Onyx.clear()is still running and hasn't fully cleared storage. - While that happens batch any new writes to storage or flag which keys need to be saved after we are done, but allow cached values to be set, merged, whatever.
- Once
Storage.clear()is done we can sync up any queued "writes" with the values in the cache.