-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from margelo/@chrispader/investigate-idb-keyv…
…al-problems Fix: nullish keys not removed/merged in IDB-Keyval (web)
- Loading branch information
Showing
5 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import _ from 'underscore'; | ||
|
||
/** | ||
* We generally want to remove top-level nullish values from objects written to disk and cache, because it decreases the amount of data stored in memory and on disk. | ||
* On native, when merging an existing value with new changes, SQLite will use JSON_PATCH, which removes top-level nullish values. | ||
* To be consistent with the behaviour for merge, we'll also want to remove nullish values for "set" operations. | ||
* On web, IndexedDB will keep the top-level keys along with a null value and this uses up storage and memory. | ||
* This method will ensure that keys for null values are removed before an object is written to disk and cache so that all platforms are storing the data in the same efficient way. | ||
* @private | ||
* @param {*} value | ||
* @returns {*} | ||
*/ | ||
function removeNullObjectValues(value) { | ||
if (_.isArray(value) || !_.isObject(value)) { | ||
return value; | ||
} | ||
|
||
const objectWithoutNullObjectValues = _.omit(value, objectValue => _.isNull(objectValue)); | ||
|
||
return objectWithoutNullObjectValues; | ||
} | ||
|
||
export default {removeNullObjectValues}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters