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

Add date comparison to replaceEqualDeep #7151

Closed
wants to merge 1 commit into from

Conversation

tran-simon
Copy link

In my project, I needed to set the structuralSharing function just to enable comparison of date objects. Before, there was no way of keeping the same reference for the same object, because any date property was considered different, even if it corresponded to the same date.

Is there a simpler way to do this? I understand that you might not want to have replaceEqualDeep handle Date objects.

In my project, I had to copy the whole code for replaceEqualDeep, isPlainArray, isPlainObject and hasObjectPrototype, because the last three functions are not exposed by @tanstack/query-core. This is a lot of copied code only to add 3 lines to replaceEqualDeep, I'm thinking that there should be a better way to extend replaceEqualDeep. Perhaps there could be a factory function that creates a replaceEqualDeep function and accepts a callback function?

Copy link

vercel bot commented Mar 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Visit Preview Mar 21, 2024 8:12pm

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1407116:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 22, 2024

I needed to set the structuralSharing function just to enable comparison of date objects

yes, that is intended. Per default, we only support json serializable values. If we add date comparison, we would also need to add Sets, and Maps, and maybe Errors, and ...

if you want that, have a look at superjson: https://github.com/blitz-js/superjson

@TkDodo TkDodo closed this Mar 22, 2024
@tran-simon
Copy link
Author

tran-simon commented Mar 22, 2024

yes, that is intended. Per default, we only support json serializable values. If we add date comparison, we would also need to add Sets, and Maps, and maybe Errors, and ...

I fully understand, however I think it would be great to have a way to configure the replaceEqualDeep function, so that we don't need to depend on yet another package!

Also, is there a reason why util functions isPlainArray, isPlainObject and hasObjectPrototype are not exported by the package?

thank you

[EDIT] Superjson is also much slower than the replaceEqualDeep implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants