This is a pseudo code for the most part. Save your shared properties somewhere.
const props = ["time", "date", "event", "artist", "organizer", "location"]
Then use this in your functions.
function editEvent(state) {
if (!props.every(p => state.form[p] !== '')) return
const event = props.reduce((acc, p) => acc[p] = state.form[p], {})
events.child(state.currentEventKey).update(event)
props.forEach(p => state.form[p] = '')
state.currentEventKey = null
state.showForm = false
}
function populateEventForm(state, payload) {
props.forEach(p => state.form[p] = payload.event[p])
state.currentEventKey = payload.key
state.showForm = true
}
Note that since you posted this as a Vue / Vuex question, you may need to use Vue.set instead of the indexer in cases, such as when building an object event. It's hard for me to say from the limited code that you posted. In this case, it will be something like
const event = props.reduce((acc, p) => {
Vue.set(acc, p, state.form[p])
return acc
}, {})
source
share