Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 22:35

    cartant on master

    docs(empty): make examples clea… (compare)

  • 22:35
    cartant closed #5148
  • 22:16
    dzhavat opened #5149
  • 21:55
    dzhavat synchronize #5148
  • 21:48

    cartant on master

    docs(scheduled): add links to s… (compare)

  • 21:48
    cartant closed #5147
  • 21:21
    dzhavat opened #5148
  • 21:20
    dzhavat opened #5147
  • 20:12
    dzhavat commented #5133
  • 20:11
    dzhavat commented #5133
  • 19:39
    dzhavat commented #5133
  • 02:42
    lock[bot] locked #5087
  • Nov 16 16:42
    lock[bot] locked #5086
  • Nov 16 09:19
    cartant commented #5146
  • Nov 16 08:28
    cartant commented #5146
  • Nov 16 08:27
    cartant commented #5146
  • Nov 16 01:55
    alshdavid commented #5126
  • Nov 15 20:18
    cartant commented #5144
  • Nov 15 16:07
    ZackDeRose commented #5144
  • Nov 15 16:05
    ZackDeRose synchronize #5144
DrewMoody
@DrewMoody
Oh, good to know about the migration guide. Also thanks a lot for the explanation on unsubscribing & completing, have been curious for a while so it's nice to get a concrete answer. I have tended to be overcautious to make sure I don't inadvertently create a leak
Dorus
@Dorus
Yeah, if you know exactly what you're doing you can get rid of a few unsubscribe/complete calls, but generally it's a good idea to err on the side of caution with those things. You make it so much easier for yourself later on too :)
Renke Grunwald
@renke
I want to subscribe to multiple observable at the same time but let them emit in order (say from left to right), a bit like merge(first$, second$) but don't let second$ emit until first$ completes. Any idea how to do this?
Dorus
@Dorus
yeah, concat to start.
Renke Grunwald
@renke
with concat, second$ is subscribed to only after first$ completes, right?
Dorus
@Dorus
yes
its going to be more complicated to buffer things
but its possible if you combine some operators
Dorus
@Dorus
easiest way is probably sourcr2.pipe(shareReplay(src2 => concat(source1,src2)))
more fancy ways are possible too
Renke Grunwald
@renke
yeah, was trying something similar, not exactly an generic approach, but I really only have two observables here, so no problem
Dorus
@Dorus
another way is to split stream two with share and then use toarray and mergeall to buffer it.
source1.pipe(publish(src1 => source2.pipe(publish(src2 =>
  concat(
    merge(
      src1,
      src2.pipe(
        takeUntil(src1Completed),
        toArray(),
        mergeAll()
    )), src2)
))))
thats probably the most fancy varriant.
@renke
Renke Grunwald
@renke
trying to understand it ;-)
Dorus
@Dorus
Let me switch to pc and format it :)
Renke Grunwald
@renke
Where is src1Completed coming from?
Dorus
@Dorus
@renke Fixed a missing ) wile formatting. The idea is to gather the output of source2 till source1completes into toArray, and then flatten it back with mergeAll

Where is src1Completed coming from?

Oops yeah i skipped over that one too. Should be something like concat(src1.pipe(ignoreElements()), of(1))

Anywawy that's enough Rx for me tonight :)
Renke Grunwald
@renke
Thanks, trying to grok it in my dreams or so I guess ;-)
Renke Grunwald
@renke
@Dorus I've never used publish with a selector as you do in the snippet you sent. Is this used so we can subscribe to source1 and source2 multiple times without actually executing the side effects multiple times?
and more specifically, I was confused about takeUntil(), I would have expected something like delayWhen() (assuming it does what I think it does)
Anton Abilov
@anton164
I recently gave a talk about how we're building our single-page application architecture with RxJS: https://www.youtube.com/watch?v=vd5S_7Qm9WE I guess we're not the first to do so, but curious to hear other people's thoughts about it :)
Renke Grunwald
@renke
@anton164 I was actually looking for stuff like that a few weeks ago, thanks for sharing
Will Mruzek
@mruzekw
If I have two observables, one of numbers and another of click events, how would I combine them to a new stream that would only emit on the click event?
const nums$ = of(0,1,2,3,4,5)
const clicks$ = fromEvent(document, 'click')

const currentNum$ = ...
For click one, it should emit 0. For click two, it should emit 1
Karsten Pruehss
@kpruehss
@mruzekw You should be able to do that using zip
Will Mruzek
@mruzekw
Thanks! I'll give that a look :pray:
Karsten Pruehss
@kpruehss
const currentNum$ = zip(nums$, clicks$).pipe(map([nums, clicks]) => ([nums, clicks]))
this should emit a tuple of the number and the associated click (if you want to just emit the numbers, or an object etc, just change the map function)
Will Mruzek
@mruzekw
It worked! Thanks
Karsten Pruehss
@kpruehss
no worries, glad it helped :)
A-STAR
@A-STAR
what does mean cum$?
Karsten Pruehss
@kpruehss
@A-STAR lol typo...thats supposed to be num$
A-STAR
@A-STAR
:D
Dorus
@Dorus

@Dorus I've never used publish with a selector as you do in the snippet you sent. Is this used so we can subscribe to source1 and source2 multiple times without actually executing the side effects multiple times?

Yes

and more specifically, I was confused about takeUntil(), I would have expected something like delayWhen() (assuming it does what I think it does)

But you cannot stop delayWhen so it would keep delaying even after you no longer need so. There used to be a pauseWhen many versions ago.
@renke

Karsten Pruehss
@kpruehss
i must have had things on my mind
Dorus
@Dorus
const currentNum$ = zip(nums$, clicks$).pipe(map([nums, clicks]) => ([nums, clicks]))

this should emit a tuple of the number and the associated click (if you want to just emit the numbers, or an object etc, just change the map function)

What does this map add exactly?

Karsten Pruehss
@kpruehss
@Dorus in this particular snippet, nothing. But if you wanted to transform the emitted value into something else, like say, only emit the numbers, or as an object literal, you'd do that through the map. I guess I could have left it off, but i didn't want to assume knowledge
@Dorus also bad wording on my part perhaps, next time i'll actually just transform the emission into something. i blame the lack of coffee
Renke Grunwald
@renke
@Dorus I've played around with your second snippet, but I couldn't get it to work; source2 values come before value from source1 and come again after the values from source1. The very first snippet you sent uses shareReplay with a selector which my RxJS version (~6.5) does not seem to support .
      const foo = first$.pipe(
        publish(firstSubject$ => {
          return second$.pipe(secondSubject$ => {
            return concat(
              merge(
                firstSubject$,
                secondSubject$.pipe(
                  takeUntil(concat(firstSubject$.pipe(ignoreElements()), of())),
                  toArray(),
                  mergeAll()
                )
              ),
              secondSubject$
            );
          });
        })
      );
const first$ = of("first1", "first2");
const second$ = of("second1", "second2");
Dorus
@Dorus
@renke You're missing an publish to create secondSubject
Renke Grunwald
@renke
oh...
Dorus
@Dorus
Like this it will subscribe to second$ twice and idk what effect that has.
Renke Grunwald
@renke
mh, I still see the values from second$ first. Is it a problem that I use of as to create my observables here?
Dorus
@Dorus

@renke https://rxviz.com/v/moY6P51O

works for me.