Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 18:25
    benlesh labeled #5183
  • 18:25
    benlesh commented #5183
  • 18:24
    benlesh opened #5183
  • 18:15

    benlesh on master

    refactor: use a lookup rather t… (compare)

  • 17:52
    benlesh closed #5016
  • 17:51

    benlesh on master

    Fix not cleared storage task ha… Merge branch 'rxmaster' Renamed ForTests to TestTools a… and 5 more (compare)

  • 17:41
    benlesh synchronize #5182
  • 16:22
    lock[bot] locked #5145
  • 06:25
    lock[bot] locked #5037
  • 00:49
    benlesh labeled #5182
  • 00:49
    benlesh labeled #5182
  • 00:49
    benlesh opened #5182
  • Dec 14 17:07
    lock[bot] locked #5127
  • Dec 14 02:08
    cartant commented #5181
  • Dec 13 21:44
    lock[bot] locked #5130
  • Dec 13 21:30
    kwonoj commented #5181
  • Dec 13 21:30
    kwonoj closed #5181
  • Dec 13 21:30
    kwonoj commented #5181
  • Dec 13 21:24
    fireflysemantics opened #5181
  • Dec 12 19:11
    lock[bot] locked #5101
SirFizX
@EricEisaman
@derekkite Thanks. I may define an on change event for my state object and use the fromEvent API.
Derek
@derekkite
@EricEisaman you likely are getting the list of users via an api call of some kind. Is it an observable or promise? There is an operator that watches for changes, let me look it up. then you can map the value to what you need
distinctUntilChange, or filter to do your own check
Dorus
@Dorus
Yes you can also directly bind the http call to an observable. Or even an websocket etc.
SirFizX
@EricEisaman
@derekkite It is a socketio msg event API.
Dorus
@Dorus
You can use the RxJs fromEvent directly on the socketio i think. No experience with it but a quick google gave me some promising results.
Derek
@derekkite
@EricEisaman yes. that can be wrapped in an observable if it isn't already, then distinctUntilChange.
SirFizX
@EricEisaman
@Dorus @derekkite Thank you for your guidance. Have a great day.
Dorus
@Dorus
Good luck :)
DrewMoody
@DrewMoody
I have two streams (A, B) I want to combine. The second stream (B) uses a result from the first stream (A) for calculations. So I need A to complete before B runs. I don't want the combined stream to emit until both have completed. Is there a creation obs to handle this? Or best to A.pipe -> switchMap to B -> map both together?
Jorrit
@jorrit-wehelp
yeah, you need switchMap
you need an emitted vaue from A to B, so if you somehow really want to wait for completion, you'd pipe on a takeLast(1) onto stream A
DrewMoody
@DrewMoody
Got it. That makes sense, thanks a lot
DrewMoody
@DrewMoody
Just curious -- Is there a way to access the original value on the chain after you use switchMap? This is how I handled:
            switchMap((A) =>
                B.pipe(
                    map((B) => ({
                        A,
                        B: { ...B, calcVal: ((A.prop / B.prop) * 100).toFixed(1) }
                    }))
                )
            ),
(by nesting) -- just wondering if there's a way to do that mapping on the original chain
Jorrit
@jorrit-wehelp
yep, an inner map is the way to handle that
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