DEV Community

Cover image for Quasar Framework - a SSR+PWA app with dynamic data.

Quasar Framework - a SSR+PWA app with dynamic data.

Tobias Mesquita on September 24, 2019

Table Of Contents 1 Introduction 2 CouchDb 3 Quasar Project 4 Preparing 4.1 Utility Belt App Extension 4.2 Installing dependencies 4...
Collapse
 
yul profile image
Yuri Lopukhov

Thank you for this article!
Is there a need for extra replication lines in Database.configure?
Documentation for pouchdb claims that

localDB.sync(remoteDB);

is equivalent to

localDB.replicate.to(remoteDB);
localDB.replicate.from(remoteDB);

Or it doesn't work correct in some cases?

Collapse
 
tobymosque profile image
Tobias Mesquita

you're right, but that isn't what we're doing here.:

try {
  await this.replicate({ source: this.remote, target: this.local })
  await this.replicate({ source: this.local, target: this.remote })
} catch (err) {

}
this.local.sync(this.remote, {
  live: true,
  retry: true
})

is equivalent to:

let sync = function () {
  this.local.sync(this.remote, {
    live: true,
    retry: true
  })
}
this.remote.replicate.to(this.local).on('complete', function () {
  this.local.replicate.to(this.remote).on('complete', function () {
    sync()
  }).on('error', function (err) {
    sync()  
  })
}).on('error', function (err) {
  sync()
})

In that case, both initial/start replications aren't running in parralel, instead of that, we're running the replication from server to local firstly. The reason behide that is, we're assuming, in the case of conflict, the server would win. So when we run the replication from local to server, the chance to appear conflicts will be very small.

So, if everything goes well, every conflict will be resolved and everything will be in sync before we start the 2-way live replication, where the conflicts probably will be resolved as soon than appear.

If you think I'm being too cautious, I'm really open to suggestions.

Collapse
 
yul profile image
Yuri Lopukhov

Hmm, I think possibility of conflicts does not depend on the order of replication, if a user tries to update an outdated record, conflict is inevitable. But perhaps how conflicts are resolved does depend on this order, I will need to test my cases to figure this out I think.

Thread Thread
 
tobymosque profile image
Tobias Mesquita

TL;DR, I'm avoiding 409 responses.

All depends on your conflict resolution strategy. I usually prioritize the server for two reasons.

The first is that the documents may have been replicated to other devices, so the unique affected device is the current one.

secondly it's cheaper to solve locally, pouchdb will not throw a 409 and force you to send other web request. at this point, you can easily ignore/delete the local document or compare both.

Collapse
 
ni9avenger profile image
Wateen Afzal • Edited

Thank you for a great article!
Database sync is working fine.
db.save is also working in seed.js
but db.rel.get('person') in pouchdb/index.js in boot folder gives following error
Cannot read property 'get' of undefined
I am using latest quasar

Collapse
 
tobymosque profile image
Tobias Mesquita

rel related methods belongs to a plug-in (relational pouch), pls, be sure u installed and configured this plug-in.

Collapse
 
ni9avenger profile image
Wateen Afzal

relational pouch in installed and configured

I fixed the issue it was due to a typo db.rel.get('person') in the screenshot of code of boot file where it should be db.local.rel.get('person')

know I am getting the issue that in the part 10.3 Listening for Changes as the listener isn't being called and when I console.log(this.listener) the listener its undefined

Thanks in advance

Collapse
 
kosirm profile image
Milan Košir • Edited

Incredibly smart and concise article. Thank you so much for this writing and code. I'm currently learning vuex-orm, which is extremely nice api for vuex management (there is excellent Luke Diebold tutorial on YouTube to get into vuex-orm quicly: youtube.com/playlist?list=PLFZAa7E...). I would like to connect vuex store to pouchdb (which is in sync with couchdb) but still use vuex-orm on the client. That way I could use all relational stuff on the client (vuex-orm.github.io/vuex-orm/guide/...). Maybe that way whole codebase could be even smaller and simple to use, because vuex-orm makes all vuex mutations under the hood. What do you think about this route?

Collapse
 
tobymosque profile image
Tobias Mesquita

I really don't know, since i never used vuex-orm, and my first impression about vuex-orm is that it was a little over-architectured for my needs. (as any first impression, that can be very biassed).

But if you're already familiarized with them, and you think would be easy to keep the module's state synced with the pouchdb, so go ahead.

Collapse
 
jimoquinn profile image
Jim O'Quinn

Just a heads up:

  • quasar ext add "@toby-mosque/utils"

Is now:

  • quasar ext add "@toby .mosque/utils"
Collapse
 
vitorhugosg profile image
Vitor Hugo Soares Gonçalves

Very nice article!

I will definitely use this knowledge for my life!

Incredible, Tobias a great professional, active and very talented!

Congratulations!