const inc$ = sources.DOM.select('.inc').events('click').mapTo(+1); const refresh$ = sources.DOM.select('.ref').events('click').startWith(0); + const sum$ = inc$.fold((x, y) => x + y, 0); + const lastSum$ = refresh$.map(_ => sum$).flatten(); - const lastSum$ = refresh$.map(_ => inc$.fold((x, y) => x + y, 0)).flatten(); const vdom$ = lastSum$.map(count => div([
flattenthe new subscriber will be added before the old one is removed ensuring the
sum$never goes down to zero subscribers, thus causing it to never reset. RxJS does synchronous unsubscribe during
switchMapthus in RxJS the
sum$would go from one down to zero subscribers temporarily before immediately adding the new subscriber and going from zero back to one subscriber (resetting it). The reset from zero subscribers would happen in either version of the code...
sum$has subscribers other than
lastSum$. No matter the lib, xstream or RxJS, in the
sum$example, the number of subscribers will never go down to zero so the stream will never get reset, whereas in the commented-out version a new stream reference (with zero existing subscribers) is created on every
sum$in that example, unless you explicitly choose it
It looks like
xs.of() is the same as 'xs.empty()'.
I was expecting
xs.of() equals to
xs.of(null) or somewhat. Now I see the actual behaviour does make sense, but at first it's not as obvious.
Maybe we should mention this in the description of
xs.of? I mean, equivalence of
xs.of() without args and
@staltz, my intuition was the same as you wrote.
As for now,
xs.of(undefined) behave differently.
xs.of() completes immediately, not emmiting anything.
undefined and completes immediately.