Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Last active May 9, 2017 16:13
Show Gist options
  • Save aaronmcadam/dddbd01003f96200429a3c3636d2c4b4 to your computer and use it in GitHub Desktop.
Save aaronmcadam/dddbd01003f96200429a3c3636d2c4b4 to your computer and use it in GitHub Desktop.
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