Last active
May 9, 2017 16:13
-
-
Save aaronmcadam/dddbd01003f96200429a3c3636d2c4b4 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
import { div, h2, p } from '@cycle/dom'; | |
import xs from 'xstream'; | |
export function App(sources) { | |
const request$ = xs.of({ | |
url: 'http://localhost:3000/ping', | |
category: 'api', | |
// progress: true, | |
}); | |
const vtree$ = sources.HTTP | |
.select('api') | |
.map((response$) => | |
response$.replaceError((error) => { | |
const res = { body: error.response }; | |
return xs.of(res); | |
}), | |
) | |
.flatten() | |
.debug((resp) => { | |
console.log('GET Response', resp); | |
}) | |
.map((res) => res.body) | |
.startWith({ | |
value: 'Loading...', | |
}) | |
.map((result) => div([h2('API data example'), p(JSON.stringify(result))])); | |
const sinks = { | |
DOM: vtree$, | |
HTTP: request$, | |
}; | |
return sinks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment