Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:15
    QimatLuo commented #5132
  • Nov 11 23:34
    cartant synchronize #5045
  • Nov 11 23:31
    cartant closed #4871
  • Nov 11 23:31
    cartant commented #4871
  • Nov 11 22:12
    kolodny opened #5138
  • Nov 11 21:58
    dependabot[bot] synchronize #5136
  • Nov 11 21:58

    dependabot[bot] on npm_and_yarn

    build(deps): bump lodash in /do… (compare)

  • Nov 11 21:58
    benlesh closed #5047
  • Nov 11 21:58
    dependabot[bot] edited #5136
  • Nov 11 21:58
    benlesh commented #5047
  • Nov 11 21:58
    dependabot[bot] edited #5136
  • Nov 11 21:58

    benlesh on master

    Upgrade RxJS to TS-3.7 (#5124) … (compare)

  • Nov 11 21:58
    benlesh closed #5124
  • Nov 11 21:56
    kolodny commented #5124
  • Nov 11 21:52
    kolodny synchronize #5124
  • Nov 11 21:18

    benlesh on master

    fix(closure): Annotate next() f… (compare)

  • Nov 11 21:18
    benlesh closed #5088
  • Nov 11 21:17
    benlesh commented #5124
  • Nov 11 21:08
    kolodny synchronize #5124
  • Nov 11 20:42
    BioPhoton edited #5128
Jorrit
@jorrit-wehelp
and no other way, well, without writing your own operator ;p
DrewMoody
@DrewMoody
Ohh haha ok, thanks again!
DrewMoody
@DrewMoody
Another quick question -- if I have a subject (a state subject, for example) should I be completing and/or unsubscribing from it directly when I want to destroy it? Or is unsubbing all subscribers sufficient?
Dorus
@Dorus
@DrewMoody There used to be resultSelectors on most operators like switchMap(a => b, (a,b) => ...) but they've all been removed to reduce the size of the library. Using inner maps like you did is actucally what you find back in the migration guide too.

Another quick question -- if I have a subject (a state subject, for example) should I be completing and/or unsubscribing from it directly when I want to destroy it? Or is unsubbing all subscribers sufficient?

Unsubscribe and complete have different effects. Compete would terminate all other subscribers too, but if your subscribers have inner streams (like inside a switchMap), those might keep going for a bit longer.
There is also a third option to use takeUntil to unsubscribe.

and/or

No need to do both. Either complete it to let it shut down gracefully or unsubscribe to put an instant stop to the stream. (It wont terminate anything, but operators will no longer call their followup, ignoring a few exceptions like finalize). (Doing both wont harm but it's not needed either.)

@DrewMoody
This message was deleted
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