-
Notifications
You must be signed in to change notification settings - Fork 17
/
example.js
37 lines (31 loc) · 962 Bytes
/
example.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
var Nanocomponent = require('nanocomponent')
var reactDom = require('react-dom')
var react = require('react')
var html = require('nanohtml')
var toReact = require('./react')
// create new nanocomponent
function Button () {
if (!(this instanceof Button)) return new Button()
this.color = null
Nanocomponent.call(this)
}
Button.prototype = Object.create(Nanocomponent.prototype)
Button.prototype.handleClick = function () {
console.log('yay')
}
Button.prototype.createElement = function ({color}) {
this.color = color
return html`
<button onclick=${this.handleClick} style="background-color: ${color}">
Click Me
</button>
`
}
// Implement conditional rendering
Button.prototype.update = function ({newColor}) {
return newColor !== this.color
}
var ReactButton = toReact(Button, react)
var el = document.createElement('div')
document.body.appendChild(el)
reactDom.render(react.createElement(ReactButton, { color: 'green' }), el)