chore: refactor firestore

This commit is contained in:
Kyle Fang
2020-02-16 16:07:07 +08:00
parent 6bed396b0a
commit 884c0a69e2
13 changed files with 232 additions and 189 deletions

View File

@@ -18,12 +18,19 @@ export function useDocAsType<T>() {
async function update(newValue: Partial<T>) {
return await doc.set(newValue, { merge: true });
}
async function listen(callback: (value: T) => void) {
return doc.onSnapshot(snapshot => {
callback(snapshot.data() as any);
});
}
async function deleteDoc() {
await doc.delete();
}
return {
ref: doc,
read,
update,
listen,
delete: deleteDoc
};
};