-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default values for do() parameters #2534
Default values for do() parameters #2534
Comments
Did you know that you can safely pass |
Not according to the signature: export declare function _do<T>(this: Observable<T>, next: (x: T) => void, error?: (e: any) => void, complete?: () => void): Observable<T>; |
It's entirely possible that the signature is incorrect, however it feels like a corner case. What would someone be trying to accomplish by calling As to |
For example to instrument a function with OpenTracing: const span = childOf.tracer().startSpan('my operation', { childOf })
return someAction()
// ... apply operators ...
.do(undefined, err => {
this.logger.error(err);
span.setTag('error', true);
span.log({ 'event': 'error', 'error.object': err });
})
.finally(() => {
span.finish();
}) this is personal taste of course, but I find the object version less readable: const span = childOf.tracer().startSpan('my operation', { childOf })
return someAction()
// ... apply operators ...
.do({ error: err => {
this.logger.error(err);
span.setTag('error', true);
span.log({ 'event': 'error', 'error.object': err });
}})
.finally(() => {
span.finish();
}) |
Unfortunately I can safely say that the shorthand operators for However you could easily make your own using augmentation for your application / library. You could even make it an npm package if you wanted! 🎉 |
as same as @david-driscoll , I don't think we'll bring back variant of |
you could add overloads for all 2^3 cases. But why would you want this? Can't you just return the source if no argument is passed? Where's the benefit to restricting it? |
Functionally it'll work as you'd described. Reason for this is mostly about explicitness of api definition signature - compare to |
this
|
@artaommahe You can use
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
promise.then()
andsubscribe()
can be called with passingundefined
as the first parameter, e.g. to only handle errors or completions.do()
requires to pass a noop function like() => undefined
. It should just have this as default value.doOnComplete
anddoOnError
shorthands would also be nice.The text was updated successfully, but these errors were encountered: