-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (25 loc) · 903 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const ideaList = document.querySelector('#idea-list');
// create element & render ideas
function renderIdea(doc){
let li = document.createElement('li');
let title = document.createElement('span');
let description = document.createElement('span');
title.classList.add("title");
title.classList.add("description");
li.setAttribute('data-id', doc.id);
title.textContent = doc.data().title;
description.textContent = doc.data().description;
li.appendChild(title);
li.appendChild(description);
ideaList.appendChild(li);
}
// getting data and updating data in realtime
db.collection('ideas').orderBy("timestamp", "desc").onSnapshot(snapshot => {
let changes = snapshot.docChanges();
changes.forEach(change => {
if(change.type == 'added'){
renderIdea(change.doc);
} else if (change.type == 'removed'){
}
});
});