-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Perform a side effect for every emission on the source Observable #54
Comments
Yes, it should be the same that I have written in Current Behavior. |
Sorry my fault
Still don't understand what is the problem with creating a new observable? It's just a wrapper around the promise returned by the task? |
It can be an utility to improve dx and useful not to create something that is unnecessary |
Maybe I understand now what you want. You want a fire and forget function that does not track if the e. g. the event you want to track was successfully transmitted. I don't think that we can add something like this to the library cause it would allow operations where we are unable to track possible errors that can occur in the these fire and forget side effects. Even in rxjs this would be a bad design. I would recommend a separate observable that handles your tracking of events. const events$ = new Subject<string>()
events$.subscribe(event => {
// Transmit here and handle errors here
})
const r = pipe(
source$,
// Save sync operation
rxTap(() => events$.next('clicked the button'))
) |
I partially agree, because |
@siuvdlec you have a point there Ok lets take a look at your functions. We can see that const chainFirstIOK = <A>(f: (a: A) => IO<void>): ((ma: Observable<A>): Observable<A>) =>
rxTap(a => f(a)())
// or with chainFirst (recommended)
const chainFirstIOK = <A>(f: (a: A) => IO<void>): ((ma: Observable<A>): Observable<A>) =>
chainFirst(a => fromIOK(f(a)))
const chainFirstTaskK = <A>(f: (a: A) => Task<void>): ((ma: Observable<A>): Observable<A>) =>
chainFirst(a => fromTaskK(f(a))) When we start adding these functions I would consider to define them also in the parent library |
🚀 Feature request
Add two new type class members (something like
chainFirstTaskK
,chainFirstIOK
) intoObservable
module to perform a side effect for every emission without creating new observableCurrent Behavior
Desired Behavior
Suggested Solution
Maybe the
tap
operator can be usedI'm not sure if the names are congruent (
chainFirstTaskK
,chainFirstIOK
)Who does this impact? Who is this for?
This is useful for me, for example when I have to send an analytics event when something happens or update URL after a filter submission
The text was updated successfully, but these errors were encountered: