Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Created January 8, 2017 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristoferjoseph/45b16850d1eaa7b8b5ac1867c58eda95 to your computer and use it in GitHub Desktop.
Save kristoferjoseph/45b16850d1eaa7b8b5ac1867c58eda95 to your computer and use it in GitHub Desktop.
Test app for nanomorph 2.0
var html = require('bel')
var nanomorph = require('nanomorph')
var cache = require('cache-element')
var stuff = [
[{
title: 1
}, {
title: 2
}, {
title: 3
}, {
title: 4
}],
[{
title: 'fwee'
}, {
title: 'fwi'
}, {
title: 'fwo'
}, {
title: 'fwum'
}],
[{
title: 'bob'
}, {
title: 'bunny'
}, {
title: 'peter'
}, {
title: 'snoop'
}]
]
var current
var main = page(stuff[0])
function component() {
return cache(
value => {
return html`
<li>
${value}
</li>
`
}
)
}
function page(arr) {
var item = component()
return html`
<div>
<ul>${
arr.map(s=> {
return item(s.title)
})
}</ul>
<button onclick=${swap}>SWANG</button>
</div>
`
}
function updatePage(arr) {
if (current !== arr) {
current = arr
nanomorph(page(arr), main)
}
}
var count = 0
function swap(e) {
e && e.preventDefault && e.preventDefault()
count++
count = count <= 2 ? count : 0
updatePage(stuff[count])
}
var root = document.querySelector('.root')
root.appendChild(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment