Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 01 21:25
    benlesh unlabeled #6696
  • Dec 01 21:25
    benlesh commented #6696
  • Dec 01 19:06

    kwonoj on master

    chore(issue): update issue temp… chore: Use Stackblitz rxjs temp… chore: Tweak label to be more c… and 4 more (compare)

  • Dec 01 19:06
    kwonoj closed #6668
  • Dec 01 19:05
    kwonoj closed #6698
  • Dec 01 19:05
    kwonoj locked #6698
  • Dec 01 19:05
    ronag edited #6698
  • Dec 01 19:05
    ronag edited #6698
  • Dec 01 19:04
    ronag commented #6698
  • Dec 01 19:04
    ronag opened #6698
  • Nov 30 21:41
    driskell commented #6696
  • Nov 30 20:52
    josepot commented #6690
  • Nov 30 20:51
    josepot commented #6690
  • Nov 30 19:33
    jakovljevic-mladen commented #6678
  • Nov 30 19:23
    benlesh commented #6678
  • Nov 30 19:22
    benlesh commented #6678
  • Nov 30 19:15
    benlesh synchronize #6696
  • Nov 30 19:15

    benlesh on ajax-cors-fixes

    chore: fix lint (compare)

  • Nov 30 19:06
    benlesh commented #6696
  • Nov 30 18:57

    benlesh on 8.x

    chore: Skip tests that sporadic… chore(deps): bump tmpl in /docs… chore(publish): 7.3.1 and 23 more (compare)

I've to submit the project and this seems like a hurdle
Derek
@derekkite
@mkamranhamid how are you calling loadmore? you are passing an observable to a function. check your function parameters
typogod
@typogod
I've made a library that has a very similar API as RxJS but works on pulling instead of pushing. Anyone wanna help me think of a cute name for it?
Tyler Eastman
@teastman
I'm new to rxjs and creating an angular service to cache the current users profile, profile updates can be sent via websocket or periodic refresh. Observables seemed to be a really clean way to allow components to bind the user's profile and send along updates whenever they come in. Searching around I had a hard time finding many examples of this specific pattern, are there any pitfalls I'm missing here?
export class ProfileService {

  private publisher: Subject<Account>;
  public profile: Observable<Account>;

  constructor(private httpClient: HttpClient) {
    this.publisher = new Subject<Account>();
    this.profile = this.publisher.pipe(
      shareReplay(1)
    );
    this.refreshProfile();
  }

  refreshProfile(): void {
    this.httpClient.get<Account>('/profile')
      .pipe(
        map<any, Account>(Account.deserialize)
      ).subscribe(account => this.publisher.next(account), err => this.publisher.error(err));
  }
}
Dorus
@Dorus
@teastman yes, i would recommand the function to return the observable and not subscribe. Right now any error will kill the subject.
if you want to add a store, add it seperate, and just next to a behaviorSubject either from the refresh function with a tap, or have an open websocket that does so.
Calling methods can either subscribe to the behaviorSubject to retrieve the current value, or subscribe to the refresh function to get the latest one, auto updating any other listener.
Tyler Eastman
@teastman
Thank you very much @Dorus that make a lot of sense, appreciate you taking the time.
Naiwei Zheng
@naiweizheng
Is there an easy debugging technique to locate the initiator of a completion/unsubscribe on an observable chain? Going through the call stack is very painful.
Derek
@derekkite

@naiweizheng you can use something like this

tap(
   v => console.log('value', v),
   err => console.log('error', err),
   () => console.log('complete')
)

insert it in the chain and it you can figure out where it is erroring out or completing

lake-toya
@lake-toya

Hey guys,
I'm a little lost right now
I want to build a fairly simple queue.
The queue should only execute one job at a time.
When it is empty it should run a scheduling function (on a x second interval) which checks, if there are new jobs

I was thinking about doing something like this, but it feels a little wrong. Can anyone help me out?

const { of, interval, empty } = require('rxjs')
const { tap, concatMap, skipWhile } = require('rxjs/operators')

const state = {
  isIdle: true,
  pendingJobs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] // mocked jobs
}

const schedule = () => {
  console.log('scheduling')
  return !!state.isIdle && state.pendingJobs.length
    ? of(state.pendingJobs[0])
    : empty()
}

const executeJob = async (i) => {
  await new Promise(resolve => setTimeout(resolve, 1500))
  return i
}

interval(500).pipe(
  skipWhile(_ => !state.isIdle),
  concatMap(schedule),
  tap(() => { state.isIdle = false }),
  concatMap(executeJob),
  tap((i) => {
    state.pendingJobs = state.pendingJobs.slice(1)
    state.isIdle = true
    console.log('done:', i)
  })
).subscribe()
lake-toya
@lake-toya
Or should I just combine the scheduling and executing into one function and use exhaustMap?
Jorrit
@jorrit-wehelp
sounds to me as pendingJobs.pipe(mergeMap(job => execute(job), MAX_CONCURRENCY)), where pendingJobs does the polling inside and just emits job (or jobs array)
or just concatMap if it's always 1
lake-toya
@lake-toya
Wouldnt pendingJobs keep emitting values even while the execution is still running?
the jobs will be pulled one at a time from a database so I only want to get new jobs when the queue is idling
interval(500).pipe(
  exhaustMap(_ => defer(() => scheduleAndExecute())), // return empty() when no new jobs are found and of(...) when a job was finished
  mergeAll(),
  tap(i => { console.log(i) })
).subscribe()
maybe something like this?
lake-toya
@lake-toya
maybe queue is the wrong term here :D
Jorrit
@jorrit-wehelp
yeah and introducing your own schedule concept is confusing, since rxjs already has its own schedulars :p
But if you get them one at a time (so the 'queue' is in the database I guess), can't you use a repeat() to resubscribe to the db get action after the job has been processed
lake-toya
@lake-toya
oh right, that would be an easy way to do it ... haha thanks
jcapil-ictdu
@jcapil-ictdu
Hello all, any resources for reactjs for beginner. thank you.
Dorus
@Dorus
@jcapil-ictdu wrong channel
bitQ2019
@bitQ2019
hello
PikaChokeMe
@PikaChokeMe
I have an array of Observable<httpData>...
Basicaly Observable<httpData>[]
how do I turn this into an Observable<httpData[]> ?
PikaChokeMe
@PikaChokeMe

I tried to say

    return of(this.jenkinsService.getArrayOfHttpData())
      .pipe(
        mergeMap((observableArray: Observable<httpData>[]) => {
          return forkJoin(...(observableArray.map((observableItem: Observable<httpData>) =>
            observableItem
          )));
        })
      );
  }

But I have like no idea what I'm doing :l

matrixbot
@matrixbot
elpdpt Ryan (Gitter): Not sure I understand your edit becuase its the same, but your solution is right for what you said first. You can simplify it also
return of(this.jenkinsService.getArrayOfHttpData())
  .pipe(
    switchMap(dataObservablesList => forkJoin(...dataObservablesList))
  );
elpdpt * Ryan (Gitter): Your solution is right for what you said first. You can simplify it also
return of(this.jenkinsService.getArrayOfHttpData())
  .pipe(
    switchMap(dataObservablesList => forkJoin(...dataObservablesList))
  );
Dorus
@Dorus
@TheeRFG Try from(arr).pipe(mergeAll())
That will make it emit all httpData's seperate. You could then add a toArray() at the end to change it to Observabel<httpData[]>, but i would probably suggest against that, the idea of RxJs is that you process async streams and handle the results as they come in, not delay till all results are ready.
StephenS
@S-Stephen

Hi, Is someone able to help me figure out what operator(s) I should be using?
I have two observables obs1 and obs2, and I want to combine their latest results only when Obs2 changes something like:

Obs1>----A----B---C----D----E-----
Obs2>--F--------------G---------H--
Out_>-----AF---------CG--------EH

What operator(s) should I use? I've considered using combineLatest, storing the last value of Obs2, and if changes emit the two values, but is this the best approach? (it doesn't feel right using a ?side effect? to track the state) and what operator should I used to 'emit' the combined values?

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)),