Last active
September 22, 2016 21:21
-
-
Save busypeoples/8741fd4cdc705a58879d8285cd18dbe6 to your computer and use it in GitHub Desktop.
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
// a basic example demonstrating the power of channels and generators | |
import React from 'react' | |
import { render } from 'react-dom' | |
import { chan, go, take, put, putAsync } from 'js-csp' | |
import { curry } from 'ramda' | |
import Counter from './Counter' | |
// helper | |
const createRender = curry((node, app) => render(app, node)) | |
// create one channel for now | |
const AppChannel = chan() | |
const doRender = createRender(document.getElementById('mountNode')) | |
// let start | |
const AppStart = ({ init, update, view }) => { | |
let model = 0 | |
const signal = action => () => { | |
model = update(action, model) | |
putAsync(AppChannel, model) | |
} | |
// initial render... | |
putAsync(AppChannel, init(model)) | |
go(function* () { | |
while(true) { | |
doRender(view(signal, yield take(AppChannel))) | |
} | |
}) | |
} | |
// start | |
AppStart(Counter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment