I have encountered an issue while trying to retrieve data from a Firestore real-time query and perform other actions. Although I am able to receive the data from Firebase as an Object, I am facing a problem when trying to access the properties of the returned Object as they appear to be empty.
Vuex Action
export const getThreadMembers = async ({ commit,dispatch }, payload) => {
try {
let members = {}
const threadMembersRef = await db.collection('members')
.doc(payload.threadId)
threadMembersRef.onSnapshot(function(doc) {
Object.assign(members,doc.data())
})
return Promise.resolve(members)
} catch (error) {
return Promise.reject(error)
}
}
/*
* this is a function for test purpose only
*/
export const delay = ({commit}) => {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(42); // After 3 seconds, resolve the promise with value 42
}, 3000);
});
}
Component file
created () {
this.getThreadMembers({
threadId: this.threadId
}).then(members => {
console.log(members)
console.log(Object.getOwnPropertyNames(members))
})
}
Question:
Why is
Object.getOwnPropertyNames(members)
executed before members
?