Commit 84b6c5fa authored by Adam Procter's avatar Adam Procter 💩

real time sync

parent 7739f53b
......@@ -35,11 +35,12 @@ const store = new Vuex.Store({
// do one way, one-off sync from the server until completion
pouchdb.replicate.from(remote).on('complete', function(info) {
// then two-way, continuous, retriable sync
// ACTION : THIS ISNT continuous ???
pouchdb
.sync(remote, { live: true, retry: true })
.on('change', function(info) {
// handle change
//console.log(info.change.docs[0].flavour)
store.commit('CHANGE_STATE', info.change.docs[0].flavour)
})
.on('paused', function(err) {
// replication paused (e.g. replication up to date, user went offline)
......@@ -56,27 +57,9 @@ const store = new Vuex.Store({
.on('error', function(err) {
// handle error
})
//The above technique results in fewer HTTP requests being used and better performance than just using db.sync on its own.
})
},
CHANGES_DBSIDE() {
pouchdb
.changes({
since: 'now',
include_docs: true
})
.on('change', function(change) {
// received a change
//console.log(change)
store.commit('CHANGE_STATE', change.doc.flavour)
})
.on('error', function(err) {
// handle errors
console.log(err)
})
},
INCOMING_CHANGE(_state, event) {
var id = 'myfav'
store.commit('CHANGE_STATE', event)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment