-
Notifications
You must be signed in to change notification settings - Fork 1
/
data-zone.js
41 lines (38 loc) · 1.04 KB
/
data-zone.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
32
33
34
35
36
37
38
39
40
41
/* exported DataZone */
/* global saveCollectedBlobs */
function DataZone(el, type) {
this.containerEl = el;
this.type = type;
this.state = {
collected: []
};
var self = this;
this.setState = function(state) {
// Merge the new state on top of the previous one and re-render everything.
this.state = Object.assign(this.state, state);
render();
}
const render = function() {
const { collected } = self.state;
const list = self.containerEl.querySelector("ul");
while (list.firstChild) {
list.removeChild(list.firstChild);
}
collected.forEach((item) => {
const li = document.createElement("li");
if (self.type === 'img') {
const img = document.createElement("img");
img.setAttribute("src", item.blobUrl);
li.appendChild(img);
}
else if (self.type === 'text') {
li.textContent = item;
}
list.appendChild(li);
});
}
this.save = function() {
const { collected } = self.state;
saveCollectedBlobs(self.type, collected)
}
}