-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.js
36 lines (36 loc) · 1.13 KB
/
List.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
import Component from "./Component.js";
import ArrayProperty from "../../node_modules/@mephiztopheles/properties/properties/ArrayProperty.js";
export default class List extends Component {
constructor(element, attributes = {}) {
super(element, attributes);
this.map = new WeakMap();
this.list = new ArrayProperty([]);
this.templateCompiler = () => {
};
this.list.addListener(() => {
this.compile();
});
}
setList(property) {
this.list.bind(property);
this.compile();
}
setTemplateCompiler(templateCompiler) {
this.templateCompiler = templateCompiler;
}
compile() {
if (this.template == null)
this.template = this.children[0].clone();
this.clear();
this.list.forEach(item => {
let element = this.map.get(item);
if (element == null) {
element = this.template.clone();
this.templateCompiler(element, item);
this.map.set(item, element);
}
this.add(element);
});
}
}
//# sourceMappingURL=List.js.map