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

Clear cache in Onyx.clear() #245

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ function clear(keysToPreserve = []) {
const defaultKeyValuePairs = _.pairs(_.omit(defaultKeyStates, keysToPreserve));

// Remove only the items that we want cleared from storage, and reset others to default
_.each(keysToBeClearedFromStorage, key => cache.drop(key));
return Storage.removeItems(keysToBeClearedFromStorage).then(() => Storage.multiSet(defaultKeyValuePairs));
});
}
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/onyxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ describe('Onyx', () => {
return Onyx.clear().then(waitForPromisesToResolve);
})
.then(() => {
// Test key should be cleared
expect(testKeyValue).toBeNull();
expect(otherTestValue).toBe(null);

// Other test key should be returned to its default state
expect(otherTestValue).toBe(42);

return Onyx.disconnect(otherTestConnectionID);
});
});
Expand Down Expand Up @@ -596,7 +600,7 @@ describe('Onyx', () => {
expect(mockCallback).toHaveBeenCalledTimes(2);

// AND the value for the first call should be null since the collection was not initialized at that point
expect(mockCallback).toHaveBeenNthCalledWith(1, null, 'testPolicy_1');
expect(mockCallback).toHaveBeenNthCalledWith(1, null, undefined);

// AND the value for the second call should be collectionUpdate since the collection was updated
expect(mockCallback).toHaveBeenNthCalledWith(2, collectionUpdate.testPolicy_1, 'testPolicy_1');
Expand Down