Commit ef3736b5 authored by Adam Procter's avatar Adam Procter 💩

live replication

parent a4e7256e
......@@ -32,12 +32,35 @@ const store = new Vuex.Store({
},
actions: {
SYNC_DB() {
console.log('sync')
pouchdb.sync(remote, { live: true, retry: true })
},
CHANGES_DBSIDE() {
console.log('yo')
// call mutation when you hear DB changes
pouchdb
.changes({
since: 'now',
include_docs: true
})
.on('change', function(change) {
// received a change
// dbupdatefav = change.doc.flavour
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)
// send change also to the pouch
pouchdb
.get('myfav')
......@@ -59,8 +82,10 @@ const store = new Vuex.Store({
pouchdb.put({ _id: id, flavour: event })
}
})
store.dispatch('CHANGES_DBSIDE')
}
},
getters: {
currentflavour: state => {
return state.flavour
......
......@@ -27,14 +27,15 @@ export default {
},
//any mutations are put into the stepfwd array
created() {
this.$store.subscribe(mutation => {
if (mutation.type !== CLEAR_STATE) {
this.stepfwd.push(mutation)
}
if (this.newMutation) {
this.stepback = []
}
})
this.$store.dispatch('CHANGES_DBSIDE'),
this.$store.subscribe(mutation => {
if (mutation.type !== CLEAR_STATE) {
this.stepfwd.push(mutation)
}
if (this.newMutation) {
this.stepback = []
}
})
},
methods: {
fwd() {
......
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