vuex-easy-firestore: Request: modifiedHook to be triggered on local change
Heya! So, I’m at a point where one vuex module needs to know when an item has changed on the server and then ask another vuex module to do some work. I am trying to use the modifiedHook
but it doesn’t seem to fire or register a “modified” trigger for me. My current, hacky workaround:
serverChange: {
convertTimestamps: {
created_at: '%convertTimestamp%',
updated_at: '%convertTimestamp%'
}
},
sync: {
patchHook: async function (updateStore, doc, store) {
await updateStore(doc)
// I don't like this! Using because the modifiedHook for serverChanges doesn't seem
// to be working...
setTimeout(async () => {
await store.dispatch('profilesData/refreshProfiles', null, { root: true })
}, 1000)
}
},
But I know this is either a misunderstanding on my part or maybe a bug? The module I want to listen to (users
) is a ‘collection’ - I’ve tried adding a modifiedHook like so:
export default {
firestorePath: 'users',
firestoreRefType: 'collection',
moduleName: 'profilesData',
statePropName: 'profiles',
namespaced: true,
serverChange: {
convertTimestamps: {
created_at: '%convertTimestamp%',
updated_at: '%convertTimestamp%'
},
modifiedHook: async function (updateStore, doc, id, store) {
console.log('I am in here') // <--- this never gets called when an item in the users collection is patched.
await updateStore(doc)
}
},
state,
getters,
actions,
mutations
}
And in the other module (at path users/{userId}
) which is a ‘doc’ type, I try making the patch that I thought should trigger the server change in users
collection:
async updateUser ({ dispatch }, userData) {
try {
await dispatch('patch', userData) // <--- this would have done a PATCH to a resource in the users collection
} catch (error) {
console.log(error)
}
},
I have verified in Firestore that the data is getting changed as I would expect - just the modifiedHook never prints that console.log.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (9 by maintainers)
@RichardCr Thank you so much for your support!! 💜 You’re my first supporter 🎉🎉🎉🎉
Feel free to open more issues whenever you’re stuck.