Created
June 5, 2015 00:23
-
-
Save artisonian/9677a6fc5301a589299d to your computer and use it in GitHub Desktop.
js-csp examples from http://jlongster.com/Taming-the-Asynchronous-Beast-with-CSP-in-JavaScript
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
Show hidden characters
{ | |
"jsxPragma": "element" | |
} |
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
node_modules | |
build/* |
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
import {element} from 'deku' | |
let propTypes = { | |
items: { | |
source: 'channelItems' | |
} | |
} | |
function render (component) { | |
let {props} = component | |
let items = props.items.map(x => <li>{x}</li>) | |
return ( | |
<ul>{items}</ul> | |
) | |
} | |
export default {propTypes, render} |
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
import 'babelify/polyfill' | |
import {chan, go, put, take, timeout} from 'js-csp' | |
import {element, tree, render} from 'deku' | |
import Container from './container' | |
let ch = chan() | |
go(function *() { | |
while (yield put(ch, 1)) yield take(timeout(250)) | |
}) | |
go(function *() { | |
while (yield put(ch, 2)) yield take(timeout(300)) | |
}) | |
go(function *() { | |
while (yield put(ch, 3)) yield take(timeout(1000)) | |
}) | |
let app = tree(<Container />) | |
app.set('channelItems', []) | |
go(function *() { | |
let items = [] | |
for (let i = 0; i < 10; i++) { | |
items.push(yield take(ch)) | |
app.set('channelItems', items) | |
} | |
ch.close() | |
}) | |
render(app, document.body) |
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
{ | |
"dependencies": { | |
"babelify": "^6.1.2", | |
"browserify": "^10.2.3", | |
"deku": "^0.4.3", | |
"js-csp": "^0.4.1" | |
}, | |
"devDependencies": { | |
"wzrd": "^1.3.0" | |
}, | |
"scripts": { | |
"build": "browserify --transform babelify --outfile build/bundle.js index.js", | |
"start": "wzrd index.js -- -t babelify -d" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment