Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 07 01:20
    cartant synchronize #5178
  • Dec 07 01:16
    cartant synchronize #5178
  • Dec 07 00:56
    cartant synchronize #5176
  • Dec 07 00:50
    cartant opened #5178
  • Dec 06 17:57
    benlesh commented #5059
  • Dec 06 17:24
    jsonberry commented #5154
  • Dec 06 17:16
    Fallenstedt commented #5154
  • Dec 06 16:51

    benlesh on master

    fix: chain subscriptions from i… (compare)

  • Dec 06 16:51
    benlesh closed #5059
  • Dec 06 11:05
    regseb edited #5177
  • Dec 06 11:01
    regseb opened #5177
  • Dec 05 21:14
    cartant commented #4494
  • Dec 05 21:13
    cartant closed #4520
  • Dec 05 21:13
    cartant commented #4520
  • Dec 05 21:13
    cartant closed #4478
  • Dec 05 21:13
    cartant commented #4478
  • Dec 05 21:12
    cartant labeled #5176
  • Dec 05 21:11
    cartant opened #5176
  • Dec 05 11:21
    aranz00 commented #5175
  • Dec 05 11:12
    aranz00 commented #5175
Delaney
@delaneyj
yeah, I found out expand is my friend for this
SirFizX
@EricEisaman
Hello RxJS community. How can I best subscribe to observed changes to the length of keys on an object?
Derek
@derekkite
@EricEisaman what are you trying to accomplish?
SirFizX
@EricEisaman
Hello @derekkite and thank you for replying. I wish to observe a state object for current users from an admin dashboard. I need only check for top level changes to the object in question so deep recursion is not required. I have developed a simple Proxy based solution but wish to integrate RxJS into my workflow soon, particularly for the functional operators.
Dorus
@Dorus
@EricEisaman RxJs itself doesn't detect object changes, but if you have an object that emit on change, you can create an observable out of those events and subscribe to that.
There are many libraries that support object change detection, angular for example does.
But a simple get/set method in TS works too.
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