Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Created March 21, 2017 22:05
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/f815c44fa1cfb802d50ff1549d766aeb to your computer and use it in GitHub Desktop.
Save kristoferjoseph/f815c44fa1cfb802d50ff1549d766aeb to your computer and use it in GitHub Desktop.
Trite component
var html = require('yo-yo')
module.exports = function Component () {
var currentState
var element
function render (state) {
if (!element) {
currentState = state
return element = create(currentState)
} else {
update(state)
}
}
function create (state) {
return html`<div>${state}</div>`
}
function update (state) {
if (currentState === state) {
return
} else {
currentState = state
}
html.update(element, create(currentState))
}
return render
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment