Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.collection('routines').get()
- .then(snap => {
- snap.forEach(doc => {
- routineList[doc.id] = {
- uid: doc.id,
- ...doc.data()
- }
- let templateList = []
- db.collection('routines').doc(doc.id).collection('templates').onSnapshot(templateSnap => {
- templateSnap.forEach(templateDoc => {
- templateList.push(templateDoc.data())
- })
- })
- routineList[doc.id].templates = templateList //templates added to each routine
- setTimeout(() => { //wait for evaluation before map
- map(routineList, routine => {
- if (routine.templates.length >= 1) {
- map(routine.templates, (template, index) => {
- if (template.dependency) {
- let dependencyIndex = routine.templates.findIndex(x => x.uid === template.dependency)
- routine.templates[index].parent = dependencyIndex
- } else {
- routine.templates[index].parent = null
- }
- })
- }
- })
- }, 500)
- })
- console.log('Routines: ', routineList)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement