-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComponents.js
More file actions
46 lines (39 loc) · 1.06 KB
/
Copy pathComponents.js
File metadata and controls
46 lines (39 loc) · 1.06 KB
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
42
43
44
45
46
'use strict';
export const Component = (function(){
/**
* Constructor del Componente
*/
const Constructor = function(options){
this.element = options.element;
this.data = options.data;
this.template = options.template;
}
// ------------- Metodos -------------
/**
* Render UI
*/
Constructor.prototype.render = function(){
const $element = document.querySelector(this.element);
if(!$element)return;
$element.innerHTML = this.template(this.data);
}
/**
* Actualizamos el Estado de forma Reactiva
*/
Constructor.prototype.setState = function(object){
for (const key in object) {
if (this.data.hasOwnProperty(key)) {
this.data[key] = object[key] ;
}
}
this.render();
}
/**
* Obtenemos una copia Inmutable del Estado
*/
Constructor.prototype.getState = function(){
return JSON.parse(JSON.stringify(this.data));
}
return Constructor;
})();
export default Component;