Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- const checkReference = ( document, path ) => document.get( path ).constructor.name === "DocumentReference";
- /**
- *
- */
- const getReferences = document => Object.keys( document.exists ? document.data() : {} ).filter( path => checkReference( document, path ) );
- /**
- *
- */
- const populate = document => {
- const references = getReferences( document )
- if ( references == 0 ) return document
- return Promise
- .all( references.map( reference => document.get( reference ).get().then( snapshot => document[ reference ] = snapshot ) ) )
- .then( () => references.forEach( reference => populate( document[ reference ] ) ) )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement