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

isDeepEqual does not work correctly for Arrays #76

Closed
codingmatty opened this issue Mar 11, 2017 · 3 comments
Closed

isDeepEqual does not work correctly for Arrays #76

codingmatty opened this issue Mar 11, 2017 · 3 comments

Comments

@codingmatty
Copy link

Case

This is a Bug.

Issue

I was trying to update an array and save the document, but it was not saving.

The culprit is within the isDeepEqual function: https://github.com/pubkey/rxdb/blob/master/src/RxDocument.js#L324
The isDeepEqual function only works if the arrays are the same length, or the original array is longer then the new array. A simple way to fix this would be to add a check for the array lengths before comparing the items in the array.

Info

  • Environment: (browser)
  • Adapter: (IndexedDB)

Code

This repl.it will demonstrate the root of the problem: https://repl.it/GRHE/0

Here is a snippet of what I was trying to do

 const accounts = await db.accountsCollection.findOne().exec();
 accounts.set('data', accounts.data.concat(newAccount));
 accounts.save().then((saved) => console.log('saved? ', saved)); // -> saved? false
 const updatedCollection = await db.accountsCollection.dump(true);
 console.dir(updatedCollection); // hasn't changed
@pubkey pubkey closed this as completed in b55a751 Mar 12, 2017
@pubkey
Copy link
Owner

pubkey commented Mar 12, 2017

Test is here

@pubkey
Copy link
Owner

pubkey commented Mar 12, 2017

@codingmatty fixed with this commit
I changed the getters so we can use the npm-module deep-equal instead of the custom comparison. This makes sure we have a well-tested deepEqual-function.

I pushed version 3.0.4 to npm. Try it out.

@codingmatty
Copy link
Author

Awesome! Thanks. I was curious why you were using a custom deepEqual function 😜 ¯_(ツ)_/¯

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