Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Choo: Fun Functional Framework

Seiya IZUMI
October 21, 2017

Choo: Fun Functional Framework

第33回 PORTもくもく会

Seiya IZUMI

October 21, 2017
Tweet

More Decks by Seiya IZUMI

Other Decks in Technology

Transcript

  1. About Me • Seiya Izumi • ෢ଂେֶ • JS, Ruby(Rails/Sinatra)


    ͱ͖Ͳ͖Golang • trainyardίϯτϦϏϡʔλʔ
  2. ΤίγεςϜ • trainyard/choo-cli … chooͷεΩϟϑΥϧσΟϯάπʔϧ • choojs/bankai … ઃఆϑΝΠϧͳ͠ͰJSόϯυϦϯά΍LiveReloadͳͲΛͯ͠ ͘ΕΔϏϧυπʔϧ

    • choojs/hyperx … ES6ͷλάɾςϯϓϨʔτ͔ΒԾ૝DOMΛੜ੒͢ΔϞδϡʔ ϧ • choojs/nanobus … ϑΝΠϧαΠζΛ࡟ͬͨEventEmitterͷ୅ସ࣮૷ • choojs/nanotick … ґଘੑͷͳ͍ process.nextTick ͷ࣮૷ ͳͲͳͲ
  3. App.js const choo = require('choo') const app = choo() app.use(require('./stores/home'))

    app.route('/', require('./pages.home')) if (module.parent) { module.exports = app } else { app.mount('body') } ϛυϧ΢ΣΞͱϧʔςΟϯάΛࢦఆͯ͠ɺDOM΁Ϛ΢ϯτ
  4. View.js const html = require('choo/html') module.exports = function (state, emit)

    { return html` <body> <h1>Hello, World!</h1> <p>If you are seeing this, then the generator works!</p> <h2>Demo</h2> <h3>${state.title}</h3> <input type="text" oninput=${update} value=${state.title} /> </body> ` function update (e) { emit('update', { value: e.target.value }) } } ES6ͷλάϦςϥϧͰDOMߏ଄Λهड़Ͱ͖Δ
  5. Store.js module.exports = function (state, emitter) { state.title = ''

    emitter.on('update', function({ value }) { state.title = value emitter.emit('render') }) } store͸ΠϕϯτϦεφఆٛͱɺstateߏ଄ͷఆٛΛߦ͏