I m trying to create a stream from an array logging inside of its map operator but it seems that something goes wrong in my code and I can't point it out...
import {Slider} from './slider/slider'
import xs from 'xstream'
export function App(sources) {
const props = {
marbles$: xs.fromArray([{
color: 'red',
x: 0
}, {
color: 'blue',
x: 20
}])
}
props.marbles$.map(item => {
console.log(item) // nothing displayed on here
return item
})
return Slider(Object.assign(sources, {props}))
}
On this little code, I m simply creating a props object containing a marbles$ stream from an array.
Just below I try to log on each item in the stream but nothing happens, and I don't understand why.
Plunker here : https://plnkr.co/edit/6uMsLIl1Edd5x670OqHa?p=preview
Nothing to show on the HTML file, only on the JS file
Any idea ?
As stated in the xstream docs, streams are idle (not executed) until they get their first listener, which is accomplished with the
addListenermethod.Notice below that the
props.marbles$.mapstream is assigned to variabley. Then they.addListenermethod is invoked. WhenaddListeneris called, theprops.marbles$.mapmethod is finally executed.Outputs in the console:
Alternatively you can put the
console.login thenextproperty of the listener instead of themapmethod:Outputs in the console:
OR, as André suggested, you can use xstream
debug:Outputs in the console: