diff --git a/lib/Onyx.js b/lib/Onyx.js index 576bd4cfb..d6b2278ed 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -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); } @@ -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)) @@ -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)