Commit 7739f53b authored by Adam Procter's avatar Adam Procter 💩

updated sync

parent 9eaae0f3
......@@ -32,12 +32,35 @@ const store = new Vuex.Store({
},
actions: {
SYNC_DB() {
pouchdb.sync(remote, { live: true, retry: true })
// 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
})
.on('paused', function(err) {
// replication paused (e.g. replication up to date, user went offline)
})
.on('active', function() {
// replicate resumed (e.g. new changes replicating, user went back online)
})
.on('denied', function(err) {
// a document failed to replicate (e.g. due to permissions)
})
.on('complete', function(info) {
// handle complete
})
.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() {
console.log('yo')
// call mutation when you hear DB changes
pouchdb
.changes({
since: 'now',
......@@ -45,8 +68,7 @@ const store = new Vuex.Store({
})
.on('change', function(change) {
// received a change
// dbupdatefav = change.doc.flavour
console.log(change)
//console.log(change)
store.commit('CHANGE_STATE', change.doc.flavour)
})
.on('error', function(err) {
......
......@@ -10,10 +10,6 @@
const CLEAR_STATE = 'CLEAR_STATE'
import EntryForm from '@/components/EntryForm.vue'
import DisplayText from '@/components/DisplayText.vue'
import PouchDB from 'pouchdb'
var pouchdb = new PouchDB('icecream')
var remote = 'https://nn.adamprocter.co.uk/icecream'
export default {
name: 'entryform',
......
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