-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement.js
48 lines (41 loc) · 1.22 KB
/
element.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
42
43
44
45
46
47
48
/**
* Simple elements that holds the bindable properties "name.firstname" and "name.lastname"
*/
class MyElement extends HTMLElement {
constructor() {
super();
this.data = {
name : {
firstname : "John"
}
};
new Binder(this,"data");
//bindable properties can be declared whenever
this.data.name.lastname = "Doe";
}
static get is() {
return "my-element"
}
connectedCallback() {
var shadow = this.attachShadow({mode: 'open'});
var div = document.createElement('div');
var firstname = document.createElement('span');
var lastname = document.createElement('span');
var divider = document.createElement('span');
divider.innerText = " - ";
div.appendChild(firstname);
div.appendChild(divider);
div.appendChild(lastname);
shadow.appendChild(div);
var inputfirst = createBindableInput();
var inputlast = document.createElement('my-input');
shadow.appendChild(inputfirst);
shadow.appendChild(inputlast);
this._bindOneWay("name.firstname", firstname, "innerText");
this._bindOneWay("name.lastname", lastname, "innerText");
this._bind("name.firstname", inputfirst, "value");
this._bind("name.lastname", inputlast, "value");
//*/
}
}
customElements.define(MyElement.is, MyElement);