Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 20 21:28
    benlesh edited #6245
  • Apr 20 21:28
    benlesh locked #6245
  • Apr 20 21:28
    benlesh labeled #6245
  • Apr 20 21:28
    benlesh opened #6245
  • Apr 20 21:05
    fcostarodrigo opened #6243
  • Apr 20 18:16
    benlesh commented #6242
  • Apr 20 18:15

    benlesh on 7.0.0-rc.2

    (compare)

  • Apr 20 18:15

    benlesh on master

    chore(publish): 7.0.0-rc.2 (compare)

  • Apr 20 17:07
    kolodny commented #6242
  • Apr 20 16:51
    benlesh commented #6242
  • Apr 20 16:51
    benlesh commented #6242
  • Apr 20 16:47
    benlesh labeled #6242
  • Apr 20 16:47
    benlesh opened #6242
  • Apr 20 16:40

    benlesh on master

    Revert "chore: Add typesVersion… (compare)

  • Apr 20 16:40
    benlesh closed #6241
  • Apr 20 16:35
    benlesh commented #6241
  • Apr 20 16:34
    benlesh opened #6241
  • Apr 20 16:34
    benlesh commented #6067
  • Apr 20 16:33
    benlesh reopened #6067
  • Apr 20 14:43
    benlesh commented #6145
freshdev1
@freshdev1
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>

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.

freshdev1
@freshdev1
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?
@Dorus thank you this helped. And it works.
Dorus
@Dorus
:+1:
Daniel Willis
@danww

@Dorus, I think this is what @freshdev1 means:

this.wrcService.getWrcBedsByFilter().pipe(
  map(beds => beds.map(bed => ({
    ...bed,
    numberOfBedsArray: Array.from({length: bed.qty}, (v, i) => i + 1),
  }))),
);

So it returns a new copy of bed, rather the modifying the exisiting one.

freshdev1
@freshdev1
@danww both works fine for me. I used what @Dorus suggested and it got the work done.
Dorus
@Dorus
@freshdev1 Yeah but @danww code avoid modifying the source, so that's a bit cleaner.
freshdev1
@freshdev1
i wanted to modify the source, as this is passed to the template and needs to have this to show the dropdown.