-
-
Save spac3unit/685a3f53bc2312ff1abea57cdb4acd9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { firestore } from './firebase' | |
| export function updateDocument(path, data) { | |
| return firestore.doc(path).update(data); | |
| } | |
| export function deleteDocument(path) { | |
| return firestore.doc(path).delete(); | |
| } | |
| export function addDocument(path = '/', collection, data) { | |
| return firestore.doc(path).collection(collection).add(data); | |
| } | |
| export function setDocument(path, data) { | |
| return firestore.doc(path).set(data); | |
| } | |
| export function snapshotDocuments(query, callback) { | |
| return query.onSnapshot(documents => { | |
| const documentsWithReference = documents.docs.map(document => ({ | |
| ...document.data(), | |
| selfReference: document.ref.path, | |
| })) | |
| callback(documentsWithReference); | |
| }) | |
| } | |
| export function queryDocuments(query, callback) { | |
| return query.get().then(documents => { | |
| const documentsWithReference = documents.docs.map(document => ({ | |
| ...document.data(), | |
| selfReference: document.ref.path, | |
| })) | |
| callback(documentsWithReference); | |
| }) | |
| } | |
| export function getDocument(path) { | |
| return firestore.doc(path); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment