Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:31
    benlesh opened #6229
  • 01:26

    benlesh on master

    feat: add (optional) defaultVal… (compare)

  • 01:26
    benlesh closed #6204
  • Apr 15 22:49
    cartant review_requested #6204
  • Apr 15 22:48
    cartant synchronize #6204
  • Apr 15 17:25

    benlesh on master

    docs: Add more detail to deprec… (compare)

  • Apr 15 16:21
    benlesh commented #6067
  • Apr 15 16:19
    benlesh commented #6067
  • Apr 15 16:17
    benlesh commented #6196
  • Apr 15 15:37

    benlesh on master

    refactor: separate fromEvent si… (compare)

  • Apr 15 15:37
    benlesh closed #6214
  • Apr 15 15:31

    benlesh on master

    fix(symbol): revert unique symb… (compare)

  • Apr 15 15:31
    benlesh closed #6224
  • Apr 15 15:31
    benlesh closed #5919
  • Apr 15 15:31

    benlesh on master

    fix: forkJoin/combineLatest ret… (compare)

  • Apr 15 15:30
    benlesh closed #6227
  • Apr 15 15:30
    benlesh closed #6226
  • Apr 15 13:25
    benlesh review_requested #6227
  • Apr 15 13:24
    benlesh synchronize #6227
  • Apr 15 01:44
    kwonoj synchronize #6224
Dorus
@Dorus
For that last reason you usually put takeUntil at the end. But there could be scenario's where you intentionally do it like this.
Yaakov Chaikin
@ychaikin
Ok, my original thought was the the scenario is only when you still want whatever output from switchMap while not wanting anymore values passed into switchMap... If I understood you correctly, that's what you are confirming as well.
Dorus
@Dorus
yes that's what you'll get
Yaakov Chaikin
@ychaikin
ok. Thanks! Appreciate your time!
freshdev1
@freshdev1
Hello guys. I am new to RxJS and is finding it a little hard to grasp a few things... Hope anyone from you can help me out with it.
Scenario:
Parent Component Contract:
     - Child Component Contract Details
     - Child component Beds details
I am getting a value from an API which I need to pass to both child components. This is how I am doing.
Parent Component (TS):
  customerInfo$: Subject<CustomerInfo> = new Subject<CustomerInfo>();

//then in a method I am doing the following
private getCustomerInfo() {
    var ucid = this.localStorageService.getCompanyUCID();

    this.accountService.GetCustomerInfoObservable(ucid)
    .subscribe(this.customerInfo$);
    //   customerInfoObj => {
    //   this.customerInfo$.next(customerInfoObj);
    // });
  }
Parent Component (HTML):
<app-contract-general-information 
          [generalInformationGroup]="contractForm.controls.BasicInformation"
          [customerInfoObj]="customerInfo$"
          (onNext)="onNext(nav,$event)"
           (selectedWrc)="setWrcObject($event)"
 ></app-contract-general-information>

<app-contract-contrcated-beds
                                    [contractedBedsFormGroup]="contractForm.controls.TenantContractDetails"
                                    [customerInfoObj]="customerInfo$"
                                    (onNext)="onNext(nav,$event)"
                                    [selectedWrc$]="selectedWrc$"
                                    ></app-contract-contrcated-beds>
freshdev1
@freshdev1

In the child this is how I am consuming:

@Input() customerInfoObj: Subject<CustomerInfo>;

this.customerInfoObj
    .subscribe(customerInfo =>{
      console.log(customerInfo);
      this.wrcList = [...customerInfo.WRC];
    })

Same goes for the second component. but nowhere does it works.

Cannot understand why both of the components are not able to get the value.
Daniel Willis
@danww
@freshdev1 Ah, I just commented on your msg in the angular/angular channel. So here, when creating wrcList, I would do something like:
this.wrcList$ = this.customerInfoObj.pipe(
  tap((customerInfo: customerInfoType) => console.log(customerInfo)), // if you need to log this.
  map((customerInfo: customerInfoType) => customerInfo.WRC),
);
freshdev1
@freshdev1
@danww lets continue over there... :smile:
Dorus
@Dorus
@freshdev1 One problem i see is that you are subscribing a subject directly to a stream. This means that when the stream completes, so does the subject. Is this intended?
Also i would not use a Subject in your situation, is there any reason why you cannot use a plain CustomerInfo instead? Or possibly an angular @output EventEmitter ?
Yaakov Chaikin
@ychaikin
If you use a takeUtil with a Subject to manage unsubscribing, do you have to call subject.complete()? I saw somewhere that you don't, but I am wondering why or why not? Can you explain this or point me to an article that speaks specifically about the complete() call on that subject and why it would (or wouldn't) be needed?
Dorus
@Dorus
@ychaikin Complete will terminate the pipeline from the subject, unsubscribe will do the same from the subscription. So what you do depend on your scenario, there is no real reason to do both however. Once a subscription is finished, all resources will be cleaned up, independent from if it was finished by a complete message or unsubscribe call.
takeUtil in fact will unsubscribe upstream and complete downstream.
Also if you complete the subject, all subscriptions will terminate (even future ones wont be able to run anymore), but if you unsubscribe, other subscription or future subscriptions could still continue.
Yaakov Chaikin
@ychaikin
@Dorus Thanks. All makes sense. I actually found a really good breakdown of when to complete and when it doesn't matter and why. Take a look if interested: https://stackoverflow.com/questions/57007118/do-i-need-to-complete-takeuntil-subject-inside-ngondestroy
Dorus
@Dorus
@ychaikin Oh you're asking about a takeUntil(subject) scenario? If i remember right there was some bug involving this a few versions back, but those should be resolved now. Anyway if you next to the subject, takeUntil will unsubscribe both the source and the inner observable.
Yaakov Chaikin
@ychaikin
@Dorus I think you're referring to shareReplay bug that was fixed.
Dorus
@Dorus
i forgot the details, it was a while back :)
Yaakov Chaikin
@ychaikin
takeUntil(subject) will unsubscribe but I was wondering about completing the subject with complete(), which is a bit different of a topic.
But I think I have it clear now. Thanks!
Dorus
@Dorus
As i said, not necessarily for the takeUntil, but you could do it if there are other subscriptions to the subject that you didn't track.
Althou i highly doubt there are any others.
Yaakov Chaikin
@ychaikin
👍
freshdev1
@freshdev1
@Dorus thank you for taking a time to look at my example. I was squarely wrong about it. @danww already guided me in another channel and I was able to get things to work. The idea was to directly send the observable to the child components and use the ASYN pipe to resolve it.
Dorus
@Dorus
@freshdev1 Ah yes that's also possible. However a bit icky. You should consider to make a service that encapsulates the observable :)
abhip5369
@abhip5369
Hi all, I am using shareReplay() to replay the http response(list of items) in different tabs on same page to fill a dropdown thats there in all the tabs, but if the value is updated from 1 of the tabs the list of items in the dropdown is not updated. Is there a way with Rxjs to achieve that ?
1 reply
Sea * Side Syndication
@sea-side-syndication
Screen Shot 2021-01-14 at 8.20.21 PM.png
what is the correct way to reconnect a websocket? what should I be putting in closeObserver to reconnect to the websocket?
Sea * Side Syndication
@sea-side-syndication
is there a thorough angular/rxjs websocket example you guys could recommend? perhaps one with multiplex?
Sea * Side Syndication
@sea-side-syndication
freshdev1
@freshdev1
Guys quick question... I think it will be easy for many, I am just new to this so struggling
 this.beds$ = this.wrcService.getWrcBedsByFilter(this.wrcId, workerTypeId, blockId, buildingId, floorId, ['100000002'])
    .pipe(
      tap(bedsResponse => console.log(bedsResponse)),
      filter(bedsResponse => bedsResponse != null),
      flatMap(beds => beds),
      map(bed => {
        bed.numberOfBedsArray = Array.from({length: bed.qty}, (v, i) => i + 1);
        return bed;
      }),
      mergeMap(beds => beds)
    );
here bedsResponse is of type Observable<Bed[]>
I am flatting it to each Bed object
Dorus
@Dorus
You can combine the last 2 calls, if you use mergeMap instead of map, you wont need the mergeMap after.
Or return Observablefrom()
freshdev1
@freshdev1
mapping it. and then want to again return Observable<Bed[]>
Dorus
@Dorus
btw flatmap and mergeMap are identical, it's strange to use both in the same code
mergeMap is the new one you should use, the other is just an allias
freshdev1
@freshdev1
Ok. I didn't know that
how to combine them all to Observable<Bed[]> again after transformation
Dorus
@Dorus
Why even split them?
this.wrcService.getWrcBedsByFilter().pipe(map(beds => beds.map(...))) should be enough right?
if you're not doing anything async inside map, you dont need Rx
freshdev1
@freshdev1
I want to update this value in each :
bed.numberOfBedsArray = Array.from({length: bed.qty}, (v, i) => i + 1);
Dorus
@Dorus
this.wrcService.getWrcBedsByFilter().pipe(map(beds => beds.map(bed => {
  bed.numberOfBedsArray = Array.from({length: bed.qty}, (v, i) => i + 1);
  return bed;
})))
Just that updating bed here is slighly dirty. Would be preferable to make a copy.
freshdev1
@freshdev1
Ok. So you mean I make a copy of the whole array
and then do this?