Created
February 5, 2022 15:33
-
-
Save kazuooooo/6379aa73b40c19c1cd27a0b7890a73a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
store.sync = (key, ref) => { | |
// Document | |
if (ref instanceof DocumentReference) { | |
return onSnapshot(ref, (ds) => { | |
if (ds.exists()) { | |
store.$patch({ [key]: ds.data() }) | |
} | |
}) | |
} | |
// Collection or Query | |
return onSnapshot(ref, (qs) => { | |
const datum = qs.docs.map(d => d.data()) | |
store.$patch((state) => { | |
state[key] = datum | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment