by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:29
    cartant labeled #5635
  • 00:28
    cartant commented #5622
  • 00:08
    cartant commented #5622
  • Aug 06 22:43
    nposener opened #5635
  • Aug 06 21:01
    thatcort commented #5622
  • Aug 06 14:42
    benlesh edited #5634
  • Aug 06 14:41
    benlesh edited #5634
  • Aug 06 14:41
    benlesh edited #5634
  • Aug 06 14:34
    benlesh commented #5634
  • Aug 06 14:34
    benlesh synchronize #5634
  • Aug 06 14:32

    benlesh on master

    test(mergeAll): add test with m… (compare)

  • Aug 06 14:32
    benlesh closed #5631
  • Aug 06 12:02
    cartant closed #5622
  • Aug 06 12:02
    cartant commented #5622
  • Aug 06 11:35
    cartant commented #5622
  • Aug 06 06:58
    cartant commented #5309
  • Aug 06 06:57
    cartant commented #5309
  • Aug 06 06:47
    josepot closed #5309
  • Aug 06 03:43
    cartant commented #5630
  • Aug 06 00:56
    benlesh commented #5621
Dorus
@Dorus
@renke
Renke Grunwald
@renke
Oh, I see, maybe was looking at shareReplay which seem to lack it indeed
Dorus
@Dorus
@renke Oops, my mistake. I named shareReplay and i also forgot to set the first 2 params. Idk i always confuse share and publish, even thou i know very well what they do.
Will Mruzek
@mruzekw

Hi there, say I have a high-order observable. It basically contains a set of set of numbers.

I'd like the first inner observable to be listened to until the next inner observable is available. Then the next one should be listened to. I know there's switchMap, but I can't seem to get it to work.

const setOfSetOfNums$ = merge(
  of([4,5,6,7]).pipe(delay(50)),
  of([0,1,2,3]),
).pipe(
  distinctUntilChanged(),
  switchMap(context => of(...context)),
)

zip(interval(1000), setOfSetOfNums$).pipe(
  map(([_, hand]) => hand),
)

I would expect this to output something like:

---0---1---4---5---6---7--->

But it spits out:

---0---1---2---3---4---5---6---7--->

Derek
@derekkite
@mruzekw not quite clear what you need. 0-1-? or 0 - 4 - 5 - 6 - 7 - 1 then what? maybe describe what you are trying to accomplish
Will Mruzek
@mruzekw
I would like the delayed observable to interrupt the non-delayed one
Thus the desired output of ---0---1---4---5---6---7--->
In actuality, it's a user event that generates a new set of nums to listen to, but this should replicate the idea...I think?
If there's a new observable in setOfSetOfNums$, we should immediately switch to that
Dorus
@Dorus
@mruzekw the problem is you zip after switchMap
thus you have them first emit all events at the same time, and then queue up at zip after the switchMap
Observables have no so called backpressure
Derek
@derekkite
of(4,5,6,7).pipe(
    delay(50), 
    switchMap((of(1,2,3,4))
)
Dorus
@Dorus
That's not even valid code
Will Mruzek
@mruzekw
@Dorus There's no way to add any backpressure?
Would it be any different if a click was the trigger to switch observables?
Derek
@derekkite
@mruzekw there are examples of a search bar where the event triggers an http call that is interrupted via switchmap if the user types something more.
Will Mruzek
@mruzekw
To make this even simpler, is there a way to receive a stream of numbers one at a time? Say when I click a button?
Karsten Pruehss
@kpruehss
@mruzekw if you want a stream of individual numbers rather then all the numbers at once, you should use from() instead of of() i think
Will Mruzek
@mruzekw
I mean, I'm sure I can create a stream of numbers with either one
The question is getting each num one at a time
Err, per click in this case
Dorus
@Dorus
@mruzekw You could put zip before the switchMap, or inside.
const setOfSetOfNums$ = merge(
  of([4,5,6,7]).pipe(delay(50)),
  of([0,1,2,3]),
).pipe(
  switchMap(context => zip(interval(1000), from(context))),
  map(([_, hand]) => hand)
)
Will Mruzek
@mruzekw
Thanks, @Dorus! That worked
Now is there a way to do a head-tail type operation on an observable?
Dorus
@Dorus
There is finalize or concat to add actions on the tail. Or just use the complete callback.
I'm not exactly sure what you mean
Will Mruzek
@mruzekw
Well, I'd like the first value of an observable to pass through, but the rest be released on click
So I was thinking I could split and merge
Something like
        return concat(
          handsToDeal$.pipe(
            first(),
            map(hand => [null, hand])
          )
          zip(dealIntent$, handsToDeal$.pipe(skip(1)))
        )
Dorus
@Dorus
zip(source, fromEvent(el, 'click').pipe(startWith()))
this does queue the clicks, that might not be intended
source.pipe(concatMap(e => fromEvent(el, 'click').pipe(mapTo(e))))
Will Mruzek
@mruzekw
startWith() without a arg just uses the first value in the stream?
Dorus
@Dorus
startWith() without an arg will emit undefined i think.
Might be better to put some value in there to avoid TS complaining, but it's not really important what you put in.
My second example with concatMap would not buffer clicks instead.
Will Mruzek
@mruzekw
Oh I see, the first is essentially a ghost click
Dorus
@Dorus
yup
Will Mruzek
@mruzekw
Thanks!
Yeah, I had to put something in for it to work
startWith(null)
Do you just pick this stuff up with experience? Or is there a good resource for thinking in streams?
Dorus
@Dorus
Both i guess
Will Mruzek
@mruzekw
Do you have a fav resource? Other than the official docs?
Dorus
@Dorus
There are good resources but you need to play with it to really get the hang of it.
I learned a lot from http://introtorx.com/ but that's Rx.net mostly.
Will Mruzek
@mruzekw
Sure, I think I get most hung up on the combination
Err, using combinations for complex interactions