Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created December 17, 2019 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/984dd2e5f06075318613b9429e1d0f46 to your computer and use it in GitHub Desktop.
Save ryanflorence/984dd2e5f06075318613b9429e1d0f46 to your computer and use it in GitHub Desktop.
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