by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:16
    cartant closed #5752
  • 08:16
    cartant commented #5752
  • 06:15
    cartant review_requested #5759
  • 06:14
    cartant edited #5759
  • 06:14
    cartant opened #5759
  • 05:42

    cartant on master

    chore: update lint-staged confiā€¦ (compare)

  • 05:42
    cartant closed #5758
  • 04:56
    cartant opened #5758
  • 02:17
    cartant review_requested #5750
  • 02:15
    cartant ready_for_review #5750
  • 02:14
    cartant synchronize #5750
  • 02:11
    cartant edited #5750
  • 02:10
    cartant synchronize #5750
  • 01:16
    cartant edited #5372
  • Sep 25 22:40
    cartant edited #5372
  • Sep 25 15:11
    alex-okrushko commented #5706
  • Sep 25 14:25
    DCtheTall commented #5702
  • Sep 25 14:02
    DCtheTall synchronize #5702
  • Sep 25 13:55
    cartant synchronize #5749
  • Sep 25 13:54
    DCtheTall synchronize #5702
Will Mruzek
@mruzekw
Err, per click in this case
Dorus
@Dorus
@mruzekw You could put zip before the switchMap, or inside.
const setOfSetOfNums$ = merge(
  of([4,5,6,7]).pipe(delay(50)),
  of([0,1,2,3]),
).pipe(
  switchMap(context => zip(interval(1000), from(context))),
  map(([_, hand]) => hand)
)
Will Mruzek
@mruzekw
Thanks, @Dorus! That worked
Now is there a way to do a head-tail type operation on an observable?
Dorus
@Dorus
There is finalize or concat to add actions on the tail. Or just use the complete callback.
I'm not exactly sure what you mean
Will Mruzek
@mruzekw
Well, I'd like the first value of an observable to pass through, but the rest be released on click
So I was thinking I could split and merge
Something like
        return concat(
          handsToDeal$.pipe(
            first(),
            map(hand => [null, hand])
          )
          zip(dealIntent$, handsToDeal$.pipe(skip(1)))
        )
Dorus
@Dorus
zip(source, fromEvent(el, 'click').pipe(startWith()))
this does queue the clicks, that might not be intended
source.pipe(concatMap(e => fromEvent(el, 'click').pipe(mapTo(e))))
Will Mruzek
@mruzekw
startWith() without a arg just uses the first value in the stream?
Dorus
@Dorus
startWith() without an arg will emit undefined i think.
Might be better to put some value in there to avoid TS complaining, but it's not really important what you put in.
My second example with concatMap would not buffer clicks instead.
Will Mruzek
@mruzekw
Oh I see, the first is essentially a ghost click
Dorus
@Dorus
yup
Will Mruzek
@mruzekw
Thanks!
Yeah, I had to put something in for it to work
startWith(null)
Do you just pick this stuff up with experience? Or is there a good resource for thinking in streams?
Dorus
@Dorus
Both i guess
Will Mruzek
@mruzekw
Do you have a fav resource? Other than the official docs?
Dorus
@Dorus
There are good resources but you need to play with it to really get the hang of it.
I learned a lot from http://introtorx.com/ but that's Rx.net mostly.
Will Mruzek
@mruzekw
Sure, I think I get most hung up on the combination
Err, using combinations for complex interactions
Dorus
@Dorus
Lets see if i can find my linkdump
Will Mruzek
@mruzekw
:D
Been a while since i checked if they where all still online.
I recently also found this playground.
Will Mruzek
@mruzekw
Thanks! I'll check these out
Nico
@ndcunningham
wow @Dorus
Dorus
@Dorus
hi @ndcunningham
Nico
@ndcunningham
:wave:
Nico
@ndcunningham
@Dorus RxJS and PouchDB have you ever done?
probably there are wrappers
Dorus
@Dorus
Never heard of PouchDB
I think it uses events? You can just use fromEvent to connect to it.
@ndcunningham Need help converting their on(...) to observable? Looks like half the api uses promises so those should combine too.
Nico
@ndcunningham
yea i was looking into it. It seems to be able to be converted, i was just wondering if you had experience :sweat_smile:
Rostero
@rostero1
this works, but is there a clearer way to do this: https://gist.github.com/rostero1/94b86bb1b154ae4b2211f2e00e4b0e0a?
the action tap and ignoreElements is what i'm looking to change
Rostero
@rostero1
maybe it's clear enough. idk actually
Dorus
@Dorus

@rostero1 I'm guessing all you want to do is register the

action$.pipe(
        filter(({ type }) => machine.handles(type)),
        tap(action => {
          service.send(action);
        })

as part of the unsubscribe chain?
Another way to do this would be to make a new observable:

return new Observable(ob => {
  let sub = state$.subscribe(ob);

  let sub2 = action$.pipe(
        filter(({ type }) => machine.handles(type)))
        subscribe(action => {
          service.send(action);
        })

  sub.add(sub2);

  return sub;
})

I leave it to you to decide if this code is any cleaner. I dont think your original is all that bad.

Dorus
@Dorus
(ps. my code samples replaces line 14-23 in yours)
Oleksandr
@kievsash
Hi, everyone. Just composed helper for mocking time-spreaded value emissions range. Maybe someone is interested: