Created
August 21, 2016 04:32
-
-
Save namelos/f72ab75d4e5fb308394786d751829bde to your computer and use it in GitHub Desktop.
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
const http = require('http') | |
const Rx = require('rxjs') | |
const main = ({ HTTP }) => ({ | |
HTTP: HTTP.map(req => `Hello ${req.url}`) | |
}) | |
const makeHttpEffect = _ => { | |
const requests$ = new Rx.Subject() | |
http.createServer((req, res) => requests$.next({ req, res })) | |
.listen(3000, _ => console.log(`listening on 3000`)) | |
return { | |
writeEffect: model$ => { | |
return model$.zip(requests$, (model, { req, res }) => ({ model, res })) | |
.subscribe(({ model, res }) => res.end(model)) | |
}, | |
readEffect: requests$.map(({ req, res }) => req) | |
} | |
} | |
const run = (main, drivers) => { | |
const sources = { HTTP: drivers.HTTP.readEffect } | |
const sinks = main(sources) | |
Object.keys(drivers).map(key => drivers[key].writeEffect(sinks[key])) | |
} | |
run(main, { HTTP: makeHttpEffect() }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment