Created
March 21, 2017 22:05
-
-
Save kristoferjoseph/f815c44fa1cfb802d50ff1549d766aeb to your computer and use it in GitHub Desktop.
Trite component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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