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

create onyx utils ts #402

Merged
merged 2 commits into from
Oct 23, 2023
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
14 changes: 14 additions & 0 deletions lib/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Merges two objects and removes null values if "shouldRemoveNullObjectValues" is set to true
*
* We generally want to remove null 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 null values for "set" operations.
*/
declare function fastMerge<T>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "fastMerge" actually a good description? Is it actually faster...? Would something like mergeWithoutNullValues make more sense? Or customMerge...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flodnv We already have fastMerge in lib/utils.js. I just declare this function in d.ts file to support ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OHhhhhh now I understand this PR much better 😂 🤦 Thanks 👍

target: T,
source: T,
shouldRemoveNullObjectValues: boolean = true
): T;

export default { fastMerge };
Loading