Skip to content

Commit 1367fb7

Browse files
authored
Update core
1 parent 72e38c3 commit 1367fb7

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Elroid.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,21 @@ class Elroid {
4343
}
4444
});
4545
}
46+
47+
update(data) {
48+
Object.assign(this.data, data);
49+
const compiledTemplate = this.compileTemplate(this.template);
50+
this.el.innerHTML = compiledTemplate;
51+
this.bindEvents();
52+
}
4653
}
4754

48-
// Component
55+
// Elroid Component
4956
class ElComponent {
5057
constructor(options) {
5158
this.template = options.template;
5259
this.data = options.data;
53-
this.el = document.createElement('div');
60+
this.el = document.querySelector(options.el);
5461

5562
this.compile();
5663
this.bindEvents();
@@ -77,14 +84,20 @@ class ElComponent {
7784
if (method && typeof method === 'function') {
7885
element.addEventListener('click', () => {
7986
method.bind(this.data)();
80-
this.compile();
81-
this.bindEvents();
8287
});
8388
}
8489
});
8590
}
91+
92+
update(data) {
93+
Object.assign(this.data, data);
94+
const compiledTemplate = this.compileTemplate(this.template);
95+
this.el.innerHTML = compiledTemplate;
96+
this.bindEvents();
97+
}
8698
}
8799

100+
// Elroid Request
88101
class ElRequest {
89102
constructor() {
90103
this.http = new XMLHttpRequest();

0 commit comments

Comments
 (0)