-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Typeahead modifies Observable prototype #1242
Comments
@achimha thnx for reporting. While I agree on the principle I would like to hear more about the exact practical problems that this is causing in your case (to properly determine priority). Would you mind elaborating. Also I'm not sure changing this will change much in practice.
This won't change even if we change code as you suggest...
Once again, agree on the principle but currently any operator in RxJS works this way. I'm trying to do a "good" thing here but would like to make sure that we are solving a real, practical problem. |
I had a very unpleasant bug in my application where it would mysteriously throw a runtime exception when run on IE11 due to a missing operator. It turned out that I had forgotten to import the RxJS operator but a 3rd party library did, although not under all circumstances! This is just an example of a side-effect that can bite you.
I went through all 3rd party libraries I depend on to look for how widespread the problem is and while it is a common problem, only some libraries do it. Angular itself is very careful to not do it. RxJS offers each operator in a prototype-changing-add-fashion and as a separate function in the typical ES6 import fashion. I do believe it is a practical problem, a library should not have side-effects, it defeats the purpose of the whole module/ES6 import paradigm. The fix is very simple and ng-bootstrap only has it in one component so if you prefer I could try my luck with a PR... |
it's not true https://github.com/ng-bootstrap/ng-bootstrap/search?utf8=%E2%9C%93&q=rxjs%2Fadd%2Fobservable |
@DzmitryShylovich the other occurrences are in demo site, which is like an app, so IMO we are fine here. I hope that you are not suggesting that we can't extend |
yeah, really, sorry didn't notice that :) |
Already asked Rob that question https://gitter.im/angular/angular?at=585322f4589f411830ed2746
|
In Javascript, it's unfortunately pretty common to leak internal implementation details to consumers. This is generally done for performance or maintainability reasons within the library. There are a few solutions for this:
The RxJS team is keenly aware of this problem, and we're trying to come up with solid solutions. There have been a few proposals. (The Observable.prototype.op method is probably the most interesting, but the issue never got any traction) |
link? |
@DzmitryShylovich oops sorry, here's the link... and it was the |
@Blesh thx :) |
Bug description:
The current code modifies the prototype of Observable in the typeahead component using statements like here:
ng-bootstrap/src/typeahead/typeahead.ts
Line 21 in cfbc24a
import 'rxjs/add/observable/fromEvent';
This is bad for several reasons. The consuming application is not aware of what is imported where and under which conditions. Also it constitutes a side effect which is generally to be avoided. The right way to do it is to import the operator as a function and use it standalone (e.g.
map.call(myObservable, ...)
), passing the Observable as an argument. An example can be found in the Angular code base:https://github.com/angular/angular/blob/master/modules/%40angular/router/src/router.ts#L20
https://github.com/angular/angular/blob/master/modules/%40angular/router/src/router.ts#L685
The text was updated successfully, but these errors were encountered: