Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 16:06
    mikezks commented #6452
  • 15:44
    mikezks commented #6452
  • 15:43
    mikezks commented #6452
  • 15:42
    mikezks commented #6452
  • Sep 19 13:44
    paulmojicatech commented #6566
  • Sep 19 12:14
    paulmojicatech synchronize #6566
  • Sep 19 12:08
    paulmojicatech synchronize #6566
  • Sep 19 12:04
    paulmojicatech synchronize #6566
  • Sep 19 12:00
    paulmojicatech synchronize #6566
  • Sep 19 07:40
    jakovljevic-mladen commented #6599
  • Sep 19 04:16
    sangxxh edited #6601
  • Sep 19 04:12
    sangxxh synchronize #6601
  • Sep 19 04:11
    sangxxh synchronize #6601
  • Sep 19 01:53
    niklas-wortmann commented #6566
  • Sep 19 01:51
    niklas-wortmann commented #6604
  • Sep 19 00:44
    benlesh labeled #6604
  • Sep 19 00:44
    benlesh opened #6604
  • Sep 19 00:41

    dependabot[bot] on npm_and_yarn

    (compare)

  • Sep 19 00:41
    benlesh review_requested #6603
  • Sep 19 00:41
    benlesh opened #6603
Dominic Watson
@intellix
this is also problematic it seems:
withLatestFrom(timer(4000)),
Dominic Watson
@intellix
ok so it seems if the withLatestFrom contains a source that hasn't emitted yet, it never gets past it
Dorus
@Dorus
@intellix yes correct, both sides need to emit before it works, and the inner observable needs to emit first. You can use strartWith to make sure there is an initial value.
typogod
@typogod
Is there a switch operator? Not switchMap, just switch.
Dorus
@Dorus
@typogod I dont understand what you're asking for
Jorrit
@jorrit-wehelp
switchMap without the Map? I'd say that is just a .map(x -> ...switch logic...) :)
typogod
@typogod
like observable.pipe(switch())
Dorus
@Dorus
@typogod I still dont understand what you're expecting
can you draw up a marble diagram of expected in and output?
typogod
@typogod
D'oh, I found it. switchAll(). Sorry for being thickheaded. :D
Dorus
@Dorus
switchAll() is just switchMap(e => e) :)
Also switchMap(selector) is pipe(map(selector), switchAll())
typogod
@typogod
I'm writing a library which is trying to follow RxJS fairly closely in terms of API and naming.
So that it will be interchangable for most people.
Dorus
@Dorus
Interesting
typogod
@typogod
I'm a big fan of the RxJS API. But I need to use iterators instead of observables, so I'm doing this.
Dorus
@Dorus
@typogod is it still async?
Or do you just run it on plain iterators? Do you know https://github.com/ReactiveX/IxJS ?
Actually that project has asyncIterator too.
typogod
@typogod
It's async, but whenever I've tried IxJS I quickly run into problems or unexpected behavior.
It simply doesn't behave closely enough to RxJS to be intuitive, but these differences aren't actually documented so you're left guessing your way through it.
Dorus
@Dorus
Ah okay. I only know it by name so I'm not sure i could help with that.
Alex
@alvipeo

hey guys! I have this Observable property in angular:

  get listIsEmpty$(): Observable<boolean | undefined> {
    if (!this._listIsEmpty$) {
      const deferredValue: Observable<boolean | undefined> = defer(() => of(this._flatNodes && this._flatNodes.length === 0));
      // initially return "undefined", then actual value (after 800 ms)
      this._listIsEmpty$ = concat(of(undefined), timer(1000).pipe(switchMapTo(deferredValue)));
    }
    return this._listIsEmpty$;
  }

and it's used in component's template with async. Now, I need it to start emitting again when my list is initialized again (this._flatNodes = <somevalue>). what's the best way of doing this?

for now I just set this._listIsEmpty$ = undefined;
Alex
@alvipeo
But I think this way async pipe will not unsubscribe correctly from the previous Observable
Robert Elliot
@Mahoney

Hi all!

I'm using rxjs with typescript and a STOMP subscription. For... reasons I can't use a STOMP error frame if the subscription can't be set up server side, so instead I send an error message on the topic.

I'm trying to work out the right way to handle that client side. At the moment I'm doing this:

interface DesiredData {
  data: string;
}
interface SubscribeError
function isDesiredData(obj: DesiredData | SubscribeError): obj is DesiredData {
  return obj.data !== undefined;
}

const stompService: RxStompService
const topic: string

const messages = stompService.watch(topic)
  .pipe(
    map((message: IFrame) => JSON.parse(message.body) as DesiredData | SubscribeError),
    takeWhile(message => isDesiredData(message), true)
  );

const [dataStream, error] = partition(messages, message => isDesiredData(message));

dataStream
  .pipe(map(it => it as DesiredData))
  .subscribe(useData.bind(this));

error
  .pipe(map(it => it as SubscribeError))
  .subscribe(notifySubscribeError.bind(this));

Is there a nicer way to handle the different message types?

Jorrit
@jorrit-wehelp
guess that depends on how you want to handle the errors...
I'd probably just let the JSON parse step throw a error and then handle it like any other error (so probably catchError) :/
Robert Elliot
@Mahoney
That's a good idea, just check the type after the parse and throw... I'll give that a try. Thanks!
Jan-Niklas W.
@niklas-wortmann
Hi everyone, on the 12th of december I am going to do a live rxjs workshop on twitch. If someone is interested, feel free to join, I would be super excited: https://twitter.com/niklas_wortmann/status/1331991104867033088
abhip5369
@abhip5369
Hi All, I am new to RxJs, and I wanted to convert the old .subscribe() way to rxjs way, but I also dont want to change my project structure. So I want to have a separate service.ts file & in component I want to simply console.log the data the way we do with .subscribe(), but in rxjs way. Is it possible to do so ? Below is a stackbliz for the same : https://stackblitz.com/edit/subscribe-pcnfrt?file=src/app/app.component.ts
Basically I still want to keep API end point call in .service.ts file & do all data manipulation with rxjs in component file. Is doing so possible ?
Daniel Willis
@danww
Daniel Willis
@danww
@abhip5369 I refactored it to work with the type of the object coming back from the API. I've also implemented search on the 'body' field, so you can see how the search term from the input field gets incorporated into the Employee Observable stream to do the filtering in the component (rather than in the template with a pipe)
Pablo Maurer
@mnewmedia_twitter
Somebody up for help? why isn't it possible to convert a promise to a observable and then use it with withLatestFrom?
      of('')
        .pipe(
          withLatestFrom(from(myPromise)),
          map((res) => {
            console.log('never resolving', res);
          })
        )
        .subscribe();
lake-toya
@lake-toya
I haven't tested the code and I'm no export so what I'm saying might be wrong.
I think your code does work, however at the point in time where withLatestFrom is being executed, the promise didn't resolve yet. This means that the latest value of your promise is nothing. withLatestFrom does not wait for the Promise or Observable to finish, it will merely take the last emitted value (if one was emitted).
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.