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

merge pouchdb-hoodie-api and pouchdb-hoodie-sync #153

Merged
merged 20 commits into from
Jun 28, 2017
Merged

Conversation

gr2m
Copy link
Member

@gr2m gr2m commented Jun 20, 2017

closes hoodiehq/camp#121, closes #149

@gr2m
Copy link
Member Author

gr2m commented Jun 20, 2017

this PR is ready for review @hoodiehq/maintainers 👀

Copy link
Contributor

@flootr flootr left a comment

Choose a reason for hiding this comment

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

@gr2m I only had a quick look because I have to go now but I'd like to have another look at the weekend though, if not someone else also wants do a review.

@@ -0,0 +1,38 @@
var utils = require('pouchdb-utils')
Copy link
Contributor

Choose a reason for hiding this comment

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

pouchdb-utils is missing in the dependencies.

This may also be the related to why this test is failing for me, because require('pouchdb-utils').extend is undefined (it seems pouchdb-utils doesn't export this method anymore https://github.com/pouchdb/pouchdb/releases/tag/6.1.1). Using pouchdb-utils@5 does work though.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, thanks 👍

@@ -0,0 +1,42 @@
var PouchDBErrors = require('pouchdb-errors')
Copy link
Contributor

Choose a reason for hiding this comment

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

pouchdb-errors is also missing in the dependencies. See my comment from above.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, thanks 👍

.catch(t.error)
})

test.only('events work on scoped APIs after reset', function (t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think .only should be removed

@gr2m
Copy link
Member Author

gr2m commented Jun 25, 2017

@flootr do still want to give it another look?

@flootr
Copy link
Contributor

flootr commented Jun 26, 2017

@gr2m Yes, I'd love to do this in the evening (cet) today if that's okay. Had no time during the weekend unfortunately :(

@gr2m
Copy link
Member Author

gr2m commented Jun 26, 2017

no problem, don’t feel pressured, it’s all good :) If you could have a look tonight that’d be great

Copy link
Contributor

@flootr flootr left a comment

Choose a reason for hiding this comment

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

@gr2m I've reviewed again and had a deeper look mostly coming up with questions, but spotted nothing serious. This PR is rather huge so it may be sensible that another person more familiar with the code base (and the tests) should have a look. Nevertheless it was fun 👍

* adds one or multiple objects to local database
*
* @param {String} prefix optional id prefix
* @param {Object|Object[]} properties Properties of one or
Copy link
Contributor

Choose a reason for hiding this comment

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

You named it properties but the param is named objects. Should we choose the same term to prevent confusion?

*/
function disconnect (state) {
if (state.replication) {
state.replication.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Afaik .cancel() is finished when the complete event is emitted by PouchDB. Is it sensible to wait for this event before resolving and/or emitting the disconnect event?

Copy link
Member Author

@gr2m gr2m Jun 27, 2017

Choose a reason for hiding this comment

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

Great catch! This didn’t cause problems so far, so I don’t think it’s critical, but I created a follow up issues for it so we don’t forget to fix it: #155

* with passed properties.
*
* @param {String} prefix optional id prefix
* @param {String|Object} idOrObject id or object with `._id` property
Copy link
Contributor

Choose a reason for hiding this comment

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

The function param says it also accepts an Array so might we extend this description?

*
* @param {String} prefix optional id prefix
* @param {String|Object} idOrObject id or object with `._id` property
* @param {Object} [properties] Optional properties if id passed
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused because the param is named newObject - if I'm not mistaken - in the function. Is it relevant to rename it to have the same term?

lib/find.js Outdated
* finds existing object in local database
*
* @param {String} prefix optional id prefix
* @param {String|Object} idOrObject Id of object or object with
Copy link
Contributor

Choose a reason for hiding this comment

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

The function accepts also an Array so should we extend the description here?


.catch(function (error) {
if (error.status === 404) {
var missing = new Error('Object with id "' + id + '" is missing')
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding my comment about error construction. Might this also be sensible to extract as a helper function if we need it at different places?

lib/update.js Outdated
* updates existing object.
*
* @param {String} prefix optional id prefix
* @param {String|Object} idOrObject id or object with `._id` property
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should cover that idOrObject/obectsOrIds also accept Arrays and unify naming, shouldn't we?

@@ -0,0 +1,4 @@
// Checks for a design doc, so we can filters out docs that shouldn't return in *All methods
module.exports = function isntDesignDoc (row) {
return row.id.match(/^_design/) === null
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a side note but I think return /^_design/.test(row.id) would be slightly faster (depending on the browser).

Copy link
Member Author

Choose a reason for hiding this comment

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

that would make a great follow-up PR 👍 do you want to send one? Thanks for checking it!

*
* @param {String} prefix String all ID’s are implicitly prefixed or
* expected to be prefixed with.
* @return {Promise}
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see this method is not returing a Promise.


if (prefix) {
options.startkey = prefix
options.endkey = prefix + '\uffff'
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this \uffff character?

Copy link
Member Author

Choose a reason for hiding this comment

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

it’s the highest Unicode character, so it makes sure it gives us all keys which start with the prefix string, see http://docs.couchdb.org/en/2.0.0/couchapp/views/collation.html#string-ranges (I don’t know why they use ufff0 instead of uffff in the example though)

}
)
return state.db.destroy()
})
Copy link
Member Author

Choose a reason for hiding this comment

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

gosh this change alone makes it all worth it already :D

@gr2m
Copy link
Member Author

gr2m commented Jun 28, 2017

this has been open long enough and I gave it thorough reviews myself, so merging it in now

@gr2m gr2m merged commit 670faa4 into master Jun 28, 2017
gr2m added a commit to hoodiehq/hoodie that referenced this pull request Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants