pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

`isDeepEqual` does not work correctly for Arrays #76

Closed codingmatty closed 7 years ago

codingmatty commented 7 years ago

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

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 commented 7 years ago

Test is here

pubkey commented 7 years ago

@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 commented 7 years ago

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