Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback changes causing issues for initWithStoredValues #99

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,8 @@ function keysChanged(collectionKey, collection) {
*
* @param {string} key
* @param {mixed} data
* @param {boolean} [hasNewValue=true]
*/
function keyChanged(key, data, hasNewValue = true) {
function keyChanged(key, data) {
// Add or remove this key from the recentlyAccessedKeys lists
if (!_.isNull(data)) {
addLastAccessedKey(key);
Expand All @@ -283,11 +282,6 @@ function keyChanged(key, data, hasNewValue = true) {
// Find all subscribers that were added with connect() and trigger the callback or setState() with the new data
_.each(callbackToStateMapping, (subscriber) => {
if (subscriber && isKeyMatch(subscriber.key, key)) {
// If data is not new then only trigger the callback or setState() for subscribers
// which are not initialized with Stored value
if (!hasNewValue && (subscriber.initWithStoredValues !== false)) {
return;
}
if (_.isFunction(subscriber.callback)) {
subscriber.callback(data, key);
}
Expand Down Expand Up @@ -479,19 +473,11 @@ function evictStorageAndRetry(error, ionMethod, ...args) {
* @returns {Promise}
*/
function set(key, val) {
const shouldCacheNewValue = !cache.hasCacheForKey(key) || !_.isEqual(val, cache.getValue(key));

// Adds the key to cache when it's not available
if (shouldCacheNewValue) {
cache.set(key, val);
}
cache.set(key, val);

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

if (!shouldCacheNewValue) {
return Promise.resolve();
}
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