I have an Object allevents
asynchronously updated with keys and values. Whenever allevents
is modified I would like to trigger a recalculation function.
To do so, I use the following Vue structure (in a component, all irrelevant elements removed):
export default {
data: function () {
return {
//
allevents: {},
events: []
}
},
methods: {
//
mqttMessage(topic, message) {
const cal = topic.split('/').pop()
this.allevents[cal] = JSON.parse(message).filter(x => true)
// following the update above, I was expecting that since
// allevents is watched below, the function would trigger
// as a workaround, I added this line below which fixes the issue
// but I still would like to understand the lack of trigger
this.computeEvents()
},
// the function ssupposed to be triggred after a chnage, below
computeEvents() {
this.events = []
Object.values(this.allevents).forEach(cal => cal.forEach(e => this.events.push(e)))
}
},
watch: {
// whenever allevents change, run computeEvents() <-- this does not happen
allevents() {
console.log("events compute triggered")
this.computeEvents()
}
},
mounted() {
//
}
}
Even though allevents
is modified and is watched, computeEvents()
is not started. Why?