Skip to content

Instantly share code, notes, and snippets.

@namelos
Created August 21, 2016 04:32
Show Gist options
  • Save namelos/f72ab75d4e5fb308394786d751829bde to your computer and use it in GitHub Desktop.
Save namelos/f72ab75d4e5fb308394786d751829bde to your computer and use it in GitHub Desktop.
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