Package Exports
- bel
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bel) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
bel
A simple library for composable DOM elements using tagged template strings.
usage
A Simple Element
Create an element:
// list.js
var $ = require('bel')
module.exports = function (items) {
return $`<ul>
${items.map(function (item) {
return $`<li>${item}</li>`
})}
</ul>`
}Then pass data to it and add to the DOM:
// app.js
var createList = require('./list.js')
var list = createList([
'grizzly',
'polar',
'brown'
])
document.body.appendChild(list)Data Down, Actions Up
// list.js
var $ = require('bel')
// The DOM is built by the data passed in
module.exports = function (items, onselected) {
function render () {
return $`<ul>
${items.map(function (item) {
return $`<li>${button(item.id, item.label)}</li>`
})}
</ul>`
}
function button (id, label) {
return $`<button onclick=${function () {
// Then action gets sent up
onselected(id)
}}>${label}</button>`
}
var element = render()
return element
}// app.js
var $ = require('bel')
var list = require('./list.js')
module.exports = function (bears) {
function onselected (id) {
// When a bear is selected, rerender with the newly selected item
// This will use DOM diffing to render, sending the data back down again
element.update(render(id))
}
function render (selected) {
return $`<div className="app">
<h1>Selected: ${selected}</h1>
${list(bears, onselected)}
</div>`
}
// On first render, we haven't selected anything
var element = render('none')
return element
}similar projects
- vel
minimal virtual-dom library - base-element
An element authoring library for creating standalone and performant elements - virtual-dom
A Virtual DOM and diffing algorithm
license
(c) 2016 Kyle Robinson Young. MIT License