Twitter | Search | |
Yassine Elouafi
playing with a hook for rxjs: useEpic combines hooks with streams (use something like epics from redux-observable) might be an alternative solution for "non trivial effects" (eg interval)
The online code editor tailored for web applications
CodeSandbox CodeSandbox @codesandbox
Reply Retweet Like More
Yassine Elouafi Feb 7
Replying to @YassineElouafi2
the idea of epic here is a function which transforms a stream of input dependencies to a stream of outputs + subscribe to outputs to perform side effects.
Reply Retweet Like
Yassine Elouafi Feb 7
Replying to @YassineElouafi2
potential benefits - epic can perform non trivial logic using rxjs operators - making dependencies explicit - stay reactive and always use latest values of dependencies
Reply Retweet Like
Oskar Hane Feb 7
Replying to @YassineElouafi2
I love the idea of this.
Reply Retweet Like
Yassine Elouafi Feb 7
Replying to @YassineElouafi2
Should've probably used the term 'sequential logic'
Reply Retweet Like
Speros Kokenes Feb 7
Replying to @YassineElouafi2
Cool solution! What are some pros/cons to doing it this way vs. useEpic() just returning the next value to a variable? I guess u can do logic on complete & error, + flexibility of your observer touching multiple values? But then it feels like you lose declarative advantage of rx
Reply Retweet Like
Yassine Elouafi Feb 7
Replying to @sperosck
useEpic is like the stream version of useEffect (whith deps provided as arguments instead of being closed over): the goal is to perform *any* kind of side effect. returning a value looks like useEpic coupled with a specific side effect (setState for the observed value).
Reply Retweet Like
Speros Kokenes Feb 7
Replying to @YassineElouafi2
Makes perfect sense, thanks
Reply Retweet Like
Francisco Tavares đŸ‡”đŸ‡± Feb 7
Replying to @YassineElouafi2
I was working on something of that nature two days ago :D Something like "redux observables" but without redux and without RxJs, it's useReducer, useEffect and Callbags as stream lib. Here:
Reply Retweet Like
Mateusz BurzyƄski Feb 7
Replying to @YassineElouafi2
whats the advantage *here* of using queueScheduler?
Reply Retweet Like
Yassine Elouafi Feb 8
Replying to @AndaristRake
Stolen from redux-observable code :) In this case didnt want many pushes to subjects to cause many observations in the same commit phase. Not sure though it's the right scheduler type
Reply Retweet Like
Mateusz BurzyƄski Feb 8
Replying to @YassineElouafi2
hm, not sure if i get the intention, but queueScheduler will flush completely before exiting the stack frame, redux-observable uses it mainly for one of the reasons saga has a scheduler - so things like this can work
Reply Retweet Like
Mateusz BurzyƄski Feb 8
Replying to @YassineElouafi2
its a little bit different from the saga scheduler though so some cases might differ in behaviour, but the idea stays the same - it's there to handle some scenarios of this class
Reply Retweet Like
Yassine Elouafi Feb 8
Replying to @AndaristRake
like when the epic uses combineLatest(x$, y$), using 'x$.next(xi); y$.next(yi)' should be notified in 1 transaction
Reply Retweet Like
Mateusz BurzyƄski Feb 8
Replying to @YassineElouafi2
i dont think this can be done with a scheduler at all in rx (might be wrong though), to achieve that combineLatest would go through smth like debounce(0), which is not ideal ofc
Reply Retweet Like
Mateusz BurzyƄski Feb 8
Replying to @YassineElouafi2
when combineLatest receives an input it cant know if it will be delivered again within the same frame, you are not filtering inputs anyhow, so maybe zip would do the trick just fine? it would wait for the other input by its definition
Reply Retweet Like
Yassine Elouafi Feb 8
Replying to @AndaristRake
makes sense! but for some reason the code seems to work (even without queueScheduler): even though I push values in 2 streams it doesn't result in 2 count increments
Reply Retweet Like
Mateusz BurzyƄski Feb 8
Replying to @YassineElouafi2
that's because your count doesnt depend directly on your inputs, ur interval rate does, put a console.log inside ur switchMap inside useEpic example and u'll notice 2 emits within 1ms timeframe when u change the slider value
Reply Retweet Like