Skip to content

Commit

Permalink
Merge pull request #82 from Expensify/amechler-next-tick-notify
Browse files Browse the repository at this point in the history
Notify subscribers on the next tick
  • Loading branch information
marcaaron authored Jun 11, 2021
2 parents 52c254f + a4401ba commit 1e82e59
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ function remove(key) {
// Cache the fact that the value was removed
cache.set(key, null);

// Optimistically inform subscribers
keyChanged(key, null);
// Optimistically inform subscribers on the next tick
Promise.resolve().then(() => keyChanged(key, null));

return AsyncStorage.removeItem(key);
}
Expand Down Expand Up @@ -516,8 +516,8 @@ function set(key, val) {
// Adds the key to cache when it's not available
cache.set(key, val);

// Optimistically inform subscribers
keyChanged(key, val);
// Optimistically inform subscribers on the next tick
Promise.resolve().then(() => keyChanged(key, val));

// Write the thing to persistent storage, which will trigger a storage event for any other tabs open on this domain
return AsyncStorage.setItem(key, JSON.stringify(val))
Expand Down Expand Up @@ -546,9 +546,9 @@ function multiSet(data) {
const keyValuePairs = prepareKeyValuePairsForStorage(data);

_.each(data, (val, key) => {
// Update cache and optimistically inform subscribers
// Update cache and optimistically inform subscribers on the next tick
cache.set(key, val);
keyChanged(key, val);
Promise.resolve().then(() => keyChanged(key, val));
});

return AsyncStorage.multiSet(keyValuePairs)
Expand Down

0 comments on commit 1e82e59

Please sign in to comment.