Advertisement
randomCodes

help

Jan 12th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. db.collection('routines').get()
  2.    .then(snap => {
  3.      snap.forEach(doc => {
  4.        routineList[doc.id] = {
  5.          uid: doc.id,
  6.          ...doc.data()
  7.        }
  8.        let templateList = []
  9.        db.collection('routines').doc(doc.id).collection('templates').onSnapshot(templateSnap => {
  10.          templateSnap.forEach(templateDoc => {
  11.            templateList.push(templateDoc.data())
  12.          })
  13.        })
  14.        routineList[doc.id].templates = templateList //templates added to each routine
  15.  
  16.        setTimeout(() => { //wait for evaluation before map
  17.          map(routineList, routine => {
  18.            if (routine.templates.length >= 1) {
  19.              map(routine.templates, (template, index) => {
  20.                if (template.dependency) {
  21.                  let dependencyIndex = routine.templates.findIndex(x => x.uid === template.dependency)
  22.                  routine.templates[index].parent = dependencyIndex
  23.                } else {
  24.                  routine.templates[index].parent = null
  25.                }
  26.              })
  27.            }
  28.          })
  29.        }, 500)
  30.      })
  31.      console.log('Routines:  ', routineList)
  32.    })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement