Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Forked from BenjaminVerble/vel-child-component
Last active August 29, 2015 14:26
Show Gist options
  • Save yoshuawuyts/721b4a13ea31e42106e8 to your computer and use it in GitHub Desktop.
Save yoshuawuyts/721b4a13ea31e42106e8 to your computer and use it in GitHub Desktop.
// main.js
const vel = require('vel')
const testElement = require('./test-element')
const el = vel(function (h, state) {
return h.html(`<div>
<h1>clicked ${String(state.n)} times</h1>
<button onclick=${onclick}>click me!</button>
${testElement(h, state, el)}
</div>`)
function onclick () {
el({ n: state.n + 1 })
}
})
document.querySelector('#content').appendChild(el({ n: 0 }))
// test-element.js
module.exports = function (h, state, el) {
return h.html(`
<button onclick=${onclick}>
child button adds two instead
</button>
`)
function onclick () {
el({ n: state.n + 2 })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment