I am trying to print the results of an HTTP request to the DOM in Cycle.js. Right now I am just trying to list the results but they will eventually be in a select dropdown.
I create the stream...
const facilityRequest$ = xs.of({
url: 'http://...',
category: 'facility'
});
Then select it...
const facilityResponse$ = sources.HTTP
.select('facility')
.flatten()
.map(res => res.body.data)
.startWith([]);
But when I try to add the results to the top like:
const vdom$ = form$.map(form =>
div([
facilityResponse$.map(res => p(res.id)),
])
);
It displays as undefined
in the browser window.
However if I add a listener and log the response to the console it displays the array of facilities:
facilityResponse$.addListener({
next: (res) => {
console.log(res);
}
})
It turns out that lists are notoriously difficult to handle with cycle.js. To do it you can either use the @cycle/collection library or map over the array elements and combine them into a single item (it depends on what you are wanting to do with it).
I solved my particular case with:
Here are some relevant discussions: