Last active
August 26, 2017 00:33
-
-
Save tttimur/f60760c675f08bba1f9ebba6ef0e7ae3 to your computer and use it in GitHub Desktop.
index.js
This file contains 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 Nanocomponent = require('nanocomponent') | |
var html = require('choo/html') | |
class Header extends Nanocomponent { | |
constructor () { | |
super () | |
this.state = null | |
this.emit = null | |
} | |
createElement(state, emit, black='') { | |
console.log('render') | |
this.state = state | |
this.emit = emit | |
return html` | |
<header class='${black} psf z4 x xjb w100 px2 py1'> | |
header | |
</header> | |
` | |
} | |
update (newState, emit) { | |
if (emit != this.emit) { | |
this.state = newState | |
this.emit = emit | |
return true | |
} else { | |
return false | |
} | |
} | |
} | |
module.exports = Header |
This file contains 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('choo/html') | |
var Header = require('./header.js') | |
var header = new Header() | |
module.exports = function (state, emitter) { | |
return html` | |
<main class="ffsans"> | |
${header.render(state, emitter)} | |
Home | |
</main> | |
` | |
} |
This file contains 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 choo = require('choo') | |
var html = require('choo/html') | |
var home = require('./home.js') | |
var post = require('./post-view.js') | |
app.route('/', home) | |
app.route('/*', post) | |
var tree = app.start() | |
document.body.appendChild(tree) |
This file contains 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('choo/html') | |
var Header = require('./header.js') | |
var header = new Header() | |
module.exports = function (state, emitter) { | |
return html` | |
<main class="ffsans"> | |
${header.render(state, emitter)} | |
Post | |
</main> | |
` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also you probably want to update based on state, not emitter. The emitter doesn't change between renders iirc. Neither does the state object instance. You should be comparing data and not top level object references.
https://gist.github.com/siiiick/f60760c675f08bba1f9ebba6ef0e7ae3#file-header-js-L24