Understanding how to set default values for an object is pretty straightforward:
store.currentUser = {
username: ''
}
And updating these values can be done like so:
store.getCurrentUser = () => {
const currentUser = Parse.User.current()
store.currentUser.username = currentUser.username
}
}
However, when dealing with an array, things get a bit more complex:
store.buildings = [
// how can we set defaults here?
]
Especially since the number of objects in the array is dynamic:
store.findBuildings = () => {
const query = new Parse.Query(Building)
return query.find({
success: (buildings) => {
// _.map(buildings, (building) => building.toJSON())
// -> [ {name: 'Name 1'}, {name: 'Name 2'}, etc... ]
// How do we update store.buildings with the new values?
},
error: (buildings, error) => {
console.log('Error:', error.message)
}
})
}
Is there a way to tackle this issue?
Please Note: Simply setting buildings = []
won't work because having default keys is essential for my app's reactivity.