-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1-element.js
64 lines (58 loc) · 1.57 KB
/
test1-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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Element as PolymerElement } from '../@polymer/polymer/polymer-element.js';
import { render } from '../lit-html/lib/lit-extended.js';
import { html } from '../lit-html/lit-html.js';
export class MyElement extends PolymerElement {
static get properties() {
return {
title: {
type: String,
value: 'hola'
},
item: {
type: Object,
value: {a:1, b:2, c:3}
},
items: {
type: Array,
value: [1, 2, 3, 4]
}
}
};
constructor() {
super();
const arrayTemplate = this.arrayTemplate();
const objectTemplate = this.objectTemplate();
const helloTemplate = this.helloTemplate('Steve');
const buttonChangeName = this.buttonChangeProperty();
render(this.pageTemplate(arrayTemplate, objectTemplate, helloTemplate, buttonChangeName), document.body);
}
pageTemplate(x, y, z, t) {
return html `<h1> Array iteration (dom-repeat)</h1>
${x}
<h1> Object iteration in attributes</h1>
${y}
<h1> Property for databinding</h1>
${z}
${t}
`;
}
arrayTemplate() {
return html `${this.forItem()}`
}
forItem() {
return this.items.map((i) => html `<h3>item: ${i}</h3>`)
}
objectTemplate() {
return html`${Object.entries(this.items)}`
}
helloTemplate(name) {
return html `<div>Hello ${name}!</div> to the document body`
}
buttonChangeProperty() {
return html `<button on-click="changeNameToBorja">Change</button>`
}
changeNameToBorja() {
this.push('items', 'Borja')
}
}
customElements.define('test1-element', MyElement);