Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 16 20:04
    ievgennaida commented #6641
  • Oct 15 20:20
    kwonoj closed #6643
  • Oct 15 20:20
    kwonoj commented #6643
  • Oct 15 20:15
    demurgos opened #6643
  • Oct 15 07:44
    demurgos opened #6642
  • Oct 15 07:26
    demurgos opened #6641
  • Oct 14 14:38
    benlesh review_requested #6640
  • Oct 14 14:37
    benlesh edited #6367
  • Oct 14 14:37
    benlesh commented #6640
  • Oct 14 14:36
    benlesh labeled #6640
  • Oct 14 14:36
    benlesh labeled #6640
  • Oct 14 14:36
    benlesh opened #6640
  • Oct 14 08:56
    jakovljevic-mladen commented #6627
  • Oct 14 08:55
    jakovljevic-mladen commented #6627
  • Oct 14 07:40
    jakovljevic-mladen edited #6627
  • Oct 13 22:24
    jakovljevic-mladen edited #6627
  • Oct 13 22:23
    jakovljevic-mladen opened #6639
  • Oct 13 21:39
    jakovljevic-mladen edited #6627
  • Oct 13 21:38
    jakovljevic-mladen opened #6638
  • Oct 13 16:18
    clydin opened #6637
matrixbot
@matrixbot
elpdpt StephenS (Gitter): It seems you can use distinctUntlChanged with custom compareFunction, checking for the first value in the array for distinction.
distinctUntilChanged((a, b) => a[0] !== b[0])
Dorus
@Dorus
@S-Stephen look at withLatestFrom
looks like
Out_ = Obs2.pipe(withLatestFrom(Obs1))
StephenS
@S-Stephen
@matrixbot @Dorus thanks both. it looks as though withLatestFrom fits the bill
Arun Gopalpuri
@arun0009
How do I forkJoin an observable of array? Do i have to convert it into an array of observable?
matrixbot
@matrixbot
elpdpt Arun Gopalpuri (Gitter): Not sure what you mean. Is the original array contains processes (observables/promises) or just values?
Arun Gopalpuri
@arun0009
@matrixbot - Okay, let me try to explain what I'm trying to do, I have a promise of users, for each user I want to get its promise(accounts), and for each account, I want to get its promise(details). I was thinking of collecting all users in an array and get accounts in parallel using forkJoin and similarly details in parallel using forkJoin.
matrixbot
@matrixbot
elpdpt @aru

elpdpt Arun Gopalpuri (Gitter): you could do that nesting of forkjoin and switchmaping.
For me its easier to have more flat liner of stream so maybe take each array emission and emit each item in the array would be easier to reason about.

Something like this:

getUsers$().pipe(
  mergeMap(users => from(users, asyncScheduler)),
  mergeMap(user => getUserAccounts(user)),
  mergeMap(accounts => from(accounts, asyncScheduler)),
  mergeMap(account => getAccountDetails(account)),
)
Arun Gopalpuri
@arun0009
@matrixbot Thanks for the clean approach with the example. I also tried to apply this same pattern but I ended up in nested pipes as I have to pass values downstream to other observables. Is there a better way of doing this? e.g.
export const getRegionClusterDetailsObservable = (region: string, ecs: AWS.ECS, elb: AWS.ELBv2, clusterPrefixes: string[]) => {
    return clusterArnsObservable(ecs, clusterPrefixes)
        .pipe(mergeMap(clusterArn => ecsListServicesObservable(ecs, clusterArn)
            .pipe(mergeMap(ecsServices => describeECSServicesObservable(ecs, ecsServices.serviceArns, clusterArn)
                .pipe(mergeMap(describeECSServicesResponse => from(describeECSServicesResponse.services)
                    .pipe(mergeMap(service => describeELBTargetHealthObservable(elb, service)
                        .pipe(mergeMap(targetHealthResponse => describeTaskDefinitionObservable(ecs, service)
                            .pipe(mergeMap(taskDefResponse => of(createClusterDetails(region, service, clusterArn, taskDefResponse, targetHealthResponse))))))))))))))
}
Bala_github
@GitHubBala23
Hi All, I am new to RxJs in Angular. And I was facing an issue while transferring data from 1 component to another. I am using a Subject in service file nd using that I m sending data user clicks on screen to another component nd display the component where data was transferred. But on the 1st load no data is transferred even though the component loads on the page
Dorus
@Dorus
@arun0009 Well the last mergeMap(e => of(e)) could just be map(e => e)
For the ones before, it's harder, you could do mergemap(e => call(e).pipe(map(r => ({...e, r})))) each time to add the new value to it.
1 reply
@GitHubBala23 you need to subscribe to a subject before you send data to it. Probably you generate the second component after the click has already been made.
Dominic Watson
@intellix
having a really weird issue using withLatestFrom() where it can't get past it
I have a source and these in the pipe:
tap(() => console.log(1)),
withLatestFrom(brandGames$.pipe(tap(() => console.log(2)))),
tap(() => console.log(3)),
it emits 1, 2........ but then doesn't emit 3 until later or not at all. I don't have any catchErrors swallowing errors

if I replace that brandGames$.pipe with this:

withLatestFrom(of([])),

then it emits

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