Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:48
    jgbpercy commented #5255
  • 13:34
    llorenspujol commented #3430
  • 10:19
    cartant commented #5259
  • 10:18
    cartant labeled #5259
  • 10:16
    kdshop edited #5259
  • 10:13
    kdshop opened #5259
  • 09:19
    robstoll commented #5258
  • 08:09
    robstoll commented #5258
  • 08:06
    cartant synchronize #5257
  • 07:41
    robstoll commented #5258
  • 07:16
    kwonoj commented #5258
  • 07:12
    robstoll commented #5258
  • 07:11
    kwonoj commented #5258
  • 07:11
    robstoll commented #5258
  • 07:10
    robstoll commented #5258
  • 07:10
    kwonoj commented #5258
  • 07:09
    robstoll commented #5258
  • 06:26
    robstoll opened #5258
  • 04:45
    cartant review_requested #5257
  • 04:45
    cartant opened #5257
Issam Maghni
@concatime
I’m trying to handle properly keyup/keydown.
this.keyup$ = fromEvent<KeyboardEvent>(this.canvas.nativeElement, 'keyup')
this.keydown$ = fromEvent<KeyboardEvent>(this.canvas.nativeElement, 'keydown')
Derek
@derekkite
@concatime then you have to type it. ((e: whatevertypeitis) => e.type)
Jorrit
@jorrit-wehelp
merge with those two would result in Observable<KeyboardEvent> ... it's correct in that not having a 'type'
I suspect it should become e.key
Issam Maghni
@concatime
Solved with
```
const i = merge(this.keyup$, this.keydown$).pipe(
      groupBy(e => e.keyCode),
      map(group => group.pipe(distinctUntilChanged(null, e => e.type))),
      mergeAll())
ghendo
@ghendo
newby here If i am using rxjs in vanilla js can I bind something in the dom to an observable?
Oleksandr
@kievsash
Can you clarify plz @ghendo ? And take alook at fromEvent operator
ghendo
@ghendo
so I would want to have say <p somethingheretosettextvalue> </p> where somethinghere is bound to the observable
Dorus
@Dorus
@ghendo Vanilla rxjs can't manipulate the DOM, but you can do things like document.getElementById("myBtn").textContent or even use jquery, or angular, to do that part of the work.
Rxjs is a query language for async events. You can use rxjs to decide when to change the DOM. In Angular, you could then even do {{ myVar | async }} to bind an observable directly to the DOM.
marcushultgren
@marcushultgren

Hi guys! Is there any "lifecycle" way to react to when other code subscribes to a BehaviorSubject I have created?

Not via pipe since that code will run after the BehaviorSubject has emitted a value. I am specifically talking about running code when "something" calls the method subscribe().

Jan-Niklas W.
@JWO719
@marcushultgren you can use the defer operator for that
marcushultgren
@marcushultgren
@JWO719 Thanks! That was exactly what I was looking for. I tried to find it via the https://rxjs-dev.firebaseapp.com/operator-decision-tree but I never saw anything about Defer there. Do you have any tips on how to find a suitable operator without having to browse through them all? :P
Siddharath Shankar Bhardwaj
@sobhardwaj
   this.sub = interval(15000)
            .subscribe(() => {
                this.getUpdates();
this.cd.detectChanges(;)
anyone can help this with inteval?? its not updating dom
Jorrit
@jorrit-wehelp
your this.getUpdates(); is a promise itself... so async, e.g. that detechtChanges will run before updates are finished
really need to chain... since this is rxjs, it would be a pipe(switchMap(....))... but could also .then(...this.cd.detectChanges) the promise :/
Siddharath Shankar Bhardwaj
@sobhardwaj
@jorrit-wehelp thanks for your early reply i got your meaning what u wanan say.
marcushultgren
@marcushultgren

The problem is not with the interval, it will fire off every 15000 ms as planned.

Just make sure to update your data correctly inside this.getUpdates so there is no need for manually running detectChanges().

Siddharath Shankar Bhardwaj
@sobhardwaj
@marcushultgren can u check i sent snippet in angular group?? in getUpdates() what i need to change
oh okey
lots of comments there ...thanks
Dorus
@Dorus
@jorrit-wehelp exhaustMap(e => this.getUpdates()) would make more sense (or mergeMap), but not switchMap as the promise does not support cancellation.

@sobhardwaj

interval(15000).pipe(
   exhaustMap(() => this.getUpdates())
 ).subscribe(() => this.cd.detectChanges())

might work.

Siddharath Shankar Bhardwaj
@sobhardwaj
@Dorus the issue is something else i think not work all these things not updating the dom....anyway i will look it
lake-toya
@lake-toya

Hey,
I want to call an API on a regular basis (every 5 seconds), but wait for the previous API call to finish.
To achieve this I did the following

timer(0, 5000).pipe(
  exhaustMap(myApiCall())
).subscribe()

This worked great but now I want to pass the data of another observable to the myApiCall method so I tried this:

const otherDataSource$ = fromEvent(something, 'event').pipe(
  startWith({ some: 'data' })
)

timer(0, 5000).pipe(
  latestFrom(otherDataSource$),
  exhaustMap(([_, data]) => myApiCall(data))
).subscribe()

I kinda get why this isn't working but I have no idea what to do. Can anyone help me out?

My end goal is it to call the API every 5 seconds (but wait for the previous API call to finish) with the latest data from the otherDataSource$ Observable

Jorrit
@jorrit-wehelp
hmm, so 5seconds after the API wait time? Would do that with a delay instead of timer
lake-toya
@lake-toya
No, I want it to be called every 5 seconds but wait for the previous request to finish so I don't have two request running at the same time. This part is working fine. My question is how to pass the latest data from otherDataSource$ into the myApiCall method.
Jorrit
@jorrit-wehelp
latestFrom -> withLatestFrom
lake-toya
@lake-toya
Oh, thats just a typo in this example
lake-toya
@lake-toya
Ok, solved it. The issue lied in the myApiCall method ... Thanks for the help
Siddharath Shankar Bhardwaj
@sobhardwaj
This message was deleted
Nico
@ndcunningham
@lake-toya if you want to wait for previous request to complete before firing off a new one shouldn't it be concatMap instead of exhaustMap ?
Dorus
@Dorus
Nah exhuastMap is ok, concatMap you risk trafficing
It really depend on how bussy your flow is
Nico
@ndcunningham
but then it would be ignored
Dorus
@Dorus
With exuahstMap you risk to not make calls for 4 minutes when one takes 6, but with concatMap you could be building up a queue instead.
Eeh, probably meant seconds not minutes :)
Nico
@ndcunningham
yea that's true depends on the API i guess
🤷‍♂️
Dorus
@Dorus
I once helped somebody here build a custon map* function that combined the best of swichMap, mergeMap, concatMap and exhaustMap. Allowed manipulation of the cancelation strategy, queue size etc.
We put it somewhere on github i think
Nico
@ndcunningham
oh wow, share when you find
It's really only to be used if the default ones are insuffisant of course :)
Nico
@ndcunningham
insufficient*
parlez vous francais?
Nico
@ndcunningham
cool @Dorus
Dorus
@Dorus
@ndcunningham Idk france :(
Meant insufficient :)