-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (34 loc) · 1.08 KB
/
index.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
import Arc, { generateModel } from './src'
class XButton extends Arc {
static get properties () {
return {
'disabled': { type: Boolean }
}
}
reconcile (dom, prevState, nextState) {
if (prevState.disabled === nextState.disabled) {
return true
}
let button = dom.querySelector('button')
nextState.disabled
? button.setAttribute('disabled', '')
: button.removeAttribute('disabled')
}
render () {
this.shadowroot.children.length && console.warn('Entire tree rendered')
let container = document.createElement('span')
let button = document.createElement('button')
button.innerText = 'Test success'
this.getAttribute('disabled') === ''
? button.setAttribute('disabled', '')
: button.removeAttribute('disabled')
container.appendChild(button)
return container
}
}
customElements.define('x-button', XButton)
let button = document.querySelector('x-button')
let model = generateModel(button, { disabled: false })
// Click to test how the model works
button.onclick = e => { model.disabled = true }
window.model = model