-
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
[Feature Request] Add optional context parameter to operators #1988
Comments
Ok sorry, taking a look at the source code I can see there are some methods that have the |
It's because binding context is being deprecated and supposed to be supported only specific api surface which corresponds to native api such as |
So in case of specific cases of map, it is supported via current impmementation. (https://github.com/ReactiveX/rxjs/blob/master/src/operator/map.ts#L38) |
As @kwonoj has stated, it's just one less part of the api surface that we're looking to support every where for all operators. With some of the more complicated operators it becomes very hard to model, especially in TypeScript. Personally I've more or less started just doing fat arrows everywhere, and that seems to work fairly well. |
@kwonoj a shame you're removing the @david-driscoll I didn't say the arrow method was a problem with the types, only bind. The problem with the arrow function (besides the unnecessary closure created) is that you need to copy over all the parameters. Consider |
Using |
Regardless, this feature has been discussed in the past, and I don't think we're going to implement it. I do appreciate your point of view and your suggestion, though. If it's okay with you, ins like to close this issue. Please feel free to reopen or comment if you'd like to continue discussion. |
|
@trxcllnt it won't transmit the types definitions in typescript and will give an error that params does not match |
If you don't use a selector function, the result will be a tuple of all the
|
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. |
Sometimes the function you want to some operators is not small, or sometimes you just want to reuse that function for multiple operators. Anyway, when you do that you end up by doing something like
.map(this.myMethod.bind(this))
or.map(value => this.myMethod(value))
.That's ok, they both work, but if you're using typescript the second will lose the return type, and the second option is too much code repeated (this case is just one param, but what about if you're expecting 2 o 3?)
Instead, it would be really helpful if you add a final optional argument with the context like this
.map(this.myMethod, this)
. This does not introduce any breaking change, and it would be super helpful to keep the typing in typescript.The text was updated successfully, but these errors were encountered: