Created
December 17, 2019 18:59
-
-
Save ryanflorence/984dd2e5f06075318613b9429e1d0f46 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
import firebase from "./firebase"; | |
import { createResource } from "./createResource"; | |
const Doc = createResource(path => | |
firebase | |
.firestore() | |
.doc(path) | |
.get() | |
.then(unwrapDoc) | |
); | |
const Collection = createResource(path => | |
firebase | |
.firestore() | |
.collection(path) | |
.get() | |
.then(unwrapCollection) | |
); | |
function unwrapCollection(collection) { | |
const arr = []; | |
collection.forEach(doc => arr.push(unwrapDoc(doc))); | |
return arr; | |
} | |
function unwrapDoc(doc) { | |
return { | |
...doc.data(), | |
id: doc.id | |
}; | |
} | |
export { Doc, Collection }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment