Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:02
    cartant closed #6485
  • 08:02

    cartant on master

    chore: use latest version of ts… (compare)

  • 08:02
    cartant closed #6486
  • 01:24
    cartant commented #6487
  • 01:24
    cartant commented #6487
  • 01:15
    mgred edited #6487
  • 01:14
    mgred opened #6487
  • 00:53
    mgred commented #6474
  • Jun 18 22:41
    cartant edited #6486
  • Jun 18 22:41
    cartant review_requested #6486
  • Jun 18 22:41
    cartant edited #6486
  • Jun 18 22:37
    cartant synchronize #6486
  • Jun 18 22:33
    cartant opened #6486
  • Jun 18 22:06
    cartant opened #6485
  • Jun 18 10:33
    akanass commented #6459
  • Jun 18 10:33
    akanass commented #6459
  • Jun 18 10:30
    akanass commented #6459
  • Jun 18 05:58
    sroucheray opened #6483
  • Jun 18 05:42
    backbone87 commented #6459
  • Jun 18 05:15
    cooperate commented #6477
lake-toya
@lake-toya
You could checkout forkJoin. It's kinda like Promise.all but for Observables
Xiang Wu
@puddlejumper26

Hi all, I would like to ask a question about fetching the json Data.
Assume the I need the results.name part. but the data is in serveral url with different page number,
starting from 1, then 2,3,4,5.. And i need to use the 'next' to obtain the next page, when 'next':'', then this is the
last page. How should I create the Observable, and use it?

{
    "next": "http://swapi.dev/api/planets/?page=2", 
    "previous": null, 
    "results": [
        {
            name: planet1
        }
        {
            ....
        }
    ]
type Planet = {
    name: string;
}

type Data = {
    next: string;
    results: Planet[];
}

getData(num: number = 1):Observable<Data>{
    return this.http.get('https://swapi.dev/api/planets/?page='+ num)
           .pipe(map(res: {next: string, results: Planet[]})=>{
               return {
                   next: res.next,
                   results: res.results,
               }
           }) 
}

then in the target component, I need to subscribe the getData method

nextData='';
planets=[];

getPlanets(){
    this.homeserve.getPlanet().subscribe(res=>{
        this.planets = res.results,
    })
}

then I could display all the name of planets from the first url (http://swapi.dev/api/planets/?page=1) on the template.

<div *ngFor = let item of planets>{{item.name}}</div>

My question is how to concat the data from the rest of pages to here (page number is unknown) Thank you!

Daniel Willis
@danww
@mnewmedia_twitter I think the reason it's not working is because of('') is never emitting. I haven't tested it, but maybe you want something like this:
from(myPromise).pipe(
  tap((res) => console.log('never resolving', res)),
).subscribe();
Pablo Maurer
@mnewmedia_twitter
@danww thanks but actually i found out of('') is emitting, but when it comes to withLatestFrom the promise just start's resolving but did not emit yet so there's no latestValue that withLatestFrom can take. But thanks for trying =)
@lake-toya Thanks you, you where right ;)
Daniel Willis
@danww
@mnewmedia_twitter Ah right. Why do you need to use withLatestFrom, rather than working directly from the from(myPromise)?
Brandt B.
@babeal
Remind me what’s the use of the second parameter to catchError? I can’t remmeber when that stream is useful
I
Daniel Willis
@danww
@babeal It's the source Observable, more detail here: https://rxjs-dev.firebaseapp.com/api/operators/catchError
Dorus
@Dorus
@babeal probably usefull when the source is cold and you want to retry?
Brandt B.
@babeal
@Dorus that’s what i was wondering but I read it different. Since the retry was being using in an effect, so inside of a switch or merge map, there was a closure around the original value that I used to redispatch the event.
matrixbot
@matrixbot
akarpov л
Norby125
@Norby125

Hi,

Which operator could I use for the next usecase?

I have a Behavior subject, I start to push data into the subject, and I would like to wait certain time (like 50-100-200ms) before hitting the subscription, then after some time, again I push data into the subject, and I would like to wait Xms before hitting the subscription, I'm only interested in the last value.

Dorus
@Dorus
@Norby125 throttle or audit
Or the variations throttleTime and auditTime ofc.
@babeal ah i only read your last comment, i didnt look at all those other things :)
Brandt B.
@babeal
@Dorus it’s all good. I’m a little rusty…
Norby125
@Norby125
which operator is like combineLatest, but does not wait for all observables to have value? So technically hits subscription whenever any of those fires
4 replies
Norby125
@Norby125

hi,

how to make sure that I unsubscribe from the observable array when the switchMap cancels the previous flow?

image.png
3 replies
I thought that switchMap will unsubscribe the previous observables where I return mouseOver and mouseOut, but I was wrong
Rostero
@rostero1
Are there any examples of bidrectional rxjs operators other than websocket?
Simone Bianchin
@powext
carbon.png
I don't understand why the second observable of concat is subscribed without waiting for the first completition
1 reply
Florian Spier
@spierala

Hi, can somebody help me with this question... https://stackoverflow.com/questions/61024321/extend-observable-and-set-external-source

It is about extending Observable and set an external source. I found NgRx doing it here:
https://github.com/ngrx/platform/blob/9.0.0/modules/store/src/store.ts#L20
However RxJS Observable gives a deprecation warning on ´Observable.source´: https://github.com/ReactiveX/rxjs/blob/6.5.5/src/internal/Observable.ts#L25

Is it safe to use source although its deprecation warning?
And is it necessary to implement lift?

here is a small stackblitz demo to play with: https://stackblitz.com/edit/extend-observable

ORES
@ORESoftware

what do I do with an empty subscription:

const sub = interval(5).subscribe()

if I omit the callbacks to subscribe, then what good is it? just curious

2 replies
ORES
@ORESoftware
Screen Shot 2020-12-26 at 3.17.04 AM.png
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.