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

mergeAndCompare array more sharply, I can't distinguish between the new and old additions. #34

Closed
productdevbook opened this issue Nov 15, 2022 · 13 comments

Comments

@productdevbook
Copy link
Contributor

productdevbook commented Nov 15, 2022

Test error: https://github.com/huntersofbook/huntersofbook/blob/29a836e9690b8c786ea89dddc55240447e016752/packages/schob/test/index.test.ts#L193

Library: https://github.com/huntersofbook/huntersofbook/tree/main/packages/schob

I created a new library using your libraries. But I have a problem with such a test.

Can you help by looking at the codes?

@mesqueeb
Copy link
Owner

@productdevbook I don't see any issues. can you send a screenshot of the error ?

@productdevbook
Copy link
Contributor Author

image

@mesqueeb
Copy link
Owner

@productdevbook is it ok for me to ask if you could add a PR that adds this failing test to my test files? It'll be easier for me to look into it this way.

@productdevbook
Copy link
Contributor Author

productdevbook commented Nov 15, 2022

Have you had time to look at the source code because I'm using your 4 libraries.

@productdevbook
Copy link
Contributor Author

productdevbook commented Nov 15, 2022

actually if i go into some detail, you add undefined without initial data in normal object, this works great.

image

But, object in array used, dont add undefined and the problem.

image

While they should be undefined in arrays, data comes in.

@mesqueeb
Copy link
Owner

Yes it's just safer if I have the same tests in the source code of this repo. It's also easier for me to debug this way. Would be a great help.

I think it's a type issue, I don't deeply merge the nested object types inside of arrays I believe. Will try to take a look this week.

@productdevbook
Copy link
Contributor Author

Can I switch npm to pnpm if you have permission ? I will send a pr for it.

and array test pr.

@mesqueeb
Copy link
Owner

@productdevbook sadly I use np to make package releases and it doesn't support pnpm. 😭 I wish I could switch as well. But np is just too awesome to create releases.

You could just add the test, I also use vitest, no need to do more testing yourself so you might be ok not installing the node modules 😁

@productdevbook
Copy link
Contributor Author

@mesqueeb
Copy link
Owner

@productdevbook I was very confused with your tests. You were using that convertTimestamps example function that I provided, but seemed to want a completely different logic... 🤔

I believe that perhaps you wanted to "merge all objects inside an array"?

If that's the case, this was already discussed in #25

it's not a default behaviour of this library, so you have to write the compare fn yourself.

That said, I have written a simple version of it for you and added that as a new test on your branch. Can you check out the latest commit in your PR and let me know if this is what you wanted?

#35

@mesqueeb
Copy link
Owner

@productdevbook thanks for your reply here
#35 (comment)

Any use case for deeply merging arrays within objects can be achieved with the mergeAndCompare function. Based on the example I gave in the tests you can tweak this function to fit your situation. There is nothing you cannot achieve with this function, your only limit is your imagination.

I will close this issue now but feel free to open a new issue if you hit any reproducible bugs. 🙌🏻

--
Merge Anything was made with 💜 by Luca Ban.
You cannot sponsor every project, but next time you do, think of this one for its prolonged maintenance.

@productdevbook
Copy link
Contributor Author

Thank you back,

Why is the content of undefined in the object not the same in the array? After all, there are objects in the array. Shouldn't it be subjected to the same function?

I think that it should be the same in the building sequence in the object.

@mesqueeb
Copy link
Owner

@productdevbook if you look closely at this line
https://github.com/mesqueeb/merge-anything/blob/production/test/mergeArrays.test.ts#L11

      .map((p, i) => (newVal[i] ? merge(p, newVal[i]) : p))

you will see that the compare function uses a nested merge call. You can tweak this logic to fit your needs by passing a nested mergeAndCompare function instead.

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

No branches or pull requests

2 participants