Created
January 17, 2017 00:26
-
-
Save ishiduca/bdbf51ad84783256b428781643c8d2fa to your computer and use it in GitHub Desktop.
yo-yo with send-action
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 d = require('global/document') | |
var onload = require('on-load') | |
var yo = require('yo-yo') | |
var sendAction = require('send-action') | |
var root = d.createElement('main') | |
var send = sendAction({ | |
onAction (state, action, data) { | |
console.log('onAction') | |
console.log(state) | |
console.log(action) | |
console.log(data) | |
if (action === 'example') { | |
return {value: data} | |
} | |
return state | |
}, | |
onChange (state, prev) { | |
console.log('onChnage') | |
console.log(state) | |
console.log(prev) | |
yo.update(root, render(state)) | |
}, | |
state: { value: 'ok' } | |
}) | |
var render = state => yo `<main>${state.value}</main>` | |
onload(root, rt => yo.update(rt, render(send.state()))) | |
d.body.appendChild(root) | |
setTimeout(() => send('example', 'hoe~'), 1000) | |
setTimeout(() => send('exile', 'EXILE'), 3000) |
Author
ishiduca
commented
Jan 17, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment