Last active
January 9, 2017 14:17
-
-
Save ishiduca/6df71e2c6daafc512ea86bcfc24dba7c to your computer and use it in GitHub Desktop.
yo-yo.js example
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 xtend = require('xtend') | |
var yo = require('yo-yo') | |
var d = require('global/document') | |
var app = require('./index') | |
var create = (state, dispatcher) => yo ` | |
<main> | |
<button onclick=${ev => dispatcher('UPDATE', +1)}>inc</button> | |
<button onclick=${ev => dispatcher('UPDATE', -1)}>dec</button> | |
<p>${state.count}</p> | |
</main> | |
` | |
var reduce = (state, action, type) => { | |
if (type === 'UPDATE') return xtend(state, {count: state.count + action}) | |
return state | |
} | |
d.body.appendChild(app({count: 0}, create, reduce)) |
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
{ | |
"scripts": { | |
"build": "browserify -t [yo-yoify] app.js > bundle.js" | |
}, | |
"dependencies": { | |
"xtend": "^4.0.1", | |
"yo-yo": "^1.3.1" | |
}, | |
"devDependencies": { | |
"yo-yoify": "^3.5.0" | |
} | |
} |
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 yo = require('yo-yo') | |
module.exports = function app (state, creator, reduce) { | |
var dom = creator(state, dispatcher) | |
return dom | |
function dispatcher (type, action) { | |
state = reduce(state, action, type) | |
yo.update(dom, creator(state, dispatcher)) | |
} | |
} | |
module.exports.html = yo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment