Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:06
    cartant assigned #5585
  • 00:10
    benlesh locked #6402
  • May 13 23:32
    cartant review_requested #6169
  • May 13 23:30
    cartant commented #6403
  • May 13 23:30

    cartant on master

    Docs: multicast deprecation (#6… (compare)

  • May 13 23:30
    cartant closed #6403
  • May 13 16:41
    backbone87 opened #6403
  • May 13 14:39
    benlesh closed #6072
  • May 13 14:39
    benlesh commented #6072
  • May 13 12:50
    cartant commented #6072
  • May 13 12:43
    cartant commented #6072
  • May 12 18:38
    kwonoj commented #6402
  • May 12 18:31
    benlesh labeled #6402
  • May 12 18:31
    benlesh opened #6402
  • May 12 17:59
    benlesh review_requested #6401
  • May 12 16:53
    benlesh labeled #6401
  • May 12 16:52
    benlesh opened #6401
  • May 12 16:42
    benlesh closed #5638
  • May 12 16:42
    benlesh commented #5638
  • May 12 16:41
    benlesh assigned #6400
ORES
@ORESoftware
Screen Shot 2020-12-26 at 3.18.16 AM.png

also what is going on here, it says when we do this:

const o = new Observer(obs => {
        // obs = o,  right?
});

that's what typescript types say?

4 replies
ORES
@ORESoftware
anyone know how to create an async queue with observables, where concurrency is a variable? this is my attempt but not sure if it's right: https://gist.github.com/ORESoftware/e73257ee495f949d2e2ce262af4bac9e
2 replies
Meai
@Meai
can somebody explain why rxjs doesnt work for me with webpack? getting tons of these errors: https://paste.centos.org/view/raw/6dc6d716
avechuche
@avechuche

Hello I have a problem. I have a "combineLatest" with 3 observables

1) onSortChange$ - is a BehaviorSubject (Mat-table sort change event (Sort class)) => emit '{sort: "name", direction: "asc"}'
2) onPageChange$ - is a BehaviorSubject (Mat-table change page event (PageEvent class)) => emit '{pageIndex: 1,2,3, ..., etc}'
3) onFilterChange$ - is a BehaviorSubject (My custom filter implementation).

When some observable emits a value, I call a service, so far, everything is perfect. What I need is that "onPageChange$" resets (again pageIndex = 1) when observable 2 or 3 change value. For example:

First values (default)

onSortChange$ = name, asc
onPageChange$ = 2
onFilterChange$ = blah blah

CALL_HTTP_WITH_PARAMETERS ("name, asc", 2, "blah blah")

// Observable 1 emit "lastName, desc" value

onSortChange$ = lastName,desc
onPageChange$ = 2 ==> has to be 1 again
onFilterChange$ = blah blah

CALL_HTTP_WITH_PARAMETERS ("lastName, desc", 1, "blah blah")

Thx

Yaakov Chaikin
@ychaikin
If you have a pipeline like this hotObservable.pipe(switchMap(value => return coldObservable)).subscribe() does the hotObservable need to be separately unsubscribed from since the cold observable will already complete and that's the observable that triggers the subscription?
Yaakov Chaikin
@ychaikin
i.e., does this scenario need an unsubscribe call at all?
Dorus
@Dorus
@ychaikin the subscription is triggered by subscribe(), not by the cold observable.
The cold observable will be called again each time hotObservable emit, until you unsubscribe.
Or you could use take, takeUntil etc. to finish the subscription at one point.
Or even keep it going forever depending on your scenario
You need an unsubscribe call when you want this pipeline to become inactive.
Yaakov Chaikin
@ychaikin
Right... what I am curious about is would it ever make sense to do this with the takeUntil:
hotObservable.pipe(takeUntil(subject), switchMap(value => return coldObservable)).subscribe()`
Note that takeUntil is NOT the last operator.
Dorus
@Dorus
it could be if you want to finish the content of the coldObservable but terminate the connection to the hotObservable. Just remember that there can be lingering activety after subject emitted.
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