shlomiassaf / ngx-modialog

Modal / Dialog for Angular
http://shlomiassaf.github.io/ngx-modialog
MIT License
686 stars 242 forks source link

Should not modify Observable prototype in library #288

Open achimha opened 7 years ago

achimha commented 7 years ago

The current code modifies the prototype of Observable using statements like here:

https://github.com/shlomiassaf/angular2-modal/blob/3884dc50e11c2f5ba3664843a806bfb55949713e/src/angular2-modal/plugins/bootstrap/modal.ts#L1

import 'rxjs/add/operator/combineLatest';

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