I have a LokiJS-provided storage which I use to update the Vuex state using mutations in the autoloadCallback
.
LokIJS storage:
var db = new loki('mydatabase', {
autoupdate: true,
autoload: true,
autoloadCallback: setupHandler
})
Vuex state and mutations:
const state = {
ads: []
}
const mutations = {
updateArray(from, to) {
from = to
},
updateAds() {
state.ads = db.getCollection('ads').data
}
}
And the callback itself:
function setupHandler() {
setupCollection('ads') // Just sets up the collection if it doesn't exist
db.getCollection('ads').insert({dummy: "Dummmy!"})
mutations.updateArray(state.ads, db.getCollection('ads').data)
mutations.updateAds()
}
The issue here is that calling the updateArray(state.ads, content)
does not change the state.ads
to content
, but the updateAds()
function which does essentially the same thing, just does not accept arguments and have them hardcoded, does change the state.ads
accordingly.
What is the underlying problem with my approach to write a general function to updateArray? Is there a way to do it?
Here is an JSFiddle MCVE example of this behaviour.