问题
There is some references of RxJS in the Angular2 project. What is RxJS being used for in Angular2?
回答1:
A list of what angular2 uses RxJS for
- Http (for example its get method returns an
Observable) - EventEmitter (like you said, extends from
Subject) - AsyncPipe which supports
Promise,ObservableorEventEmitter. - QueryList's changes method returns an
EventEmitter. Update - NG_ASYNC_VALIDATORS which implements Validator and overrides the method
validateto return either aPromiseor anObservable. Update
Note about NG_ASYNC_VALIDATORS
NG_ASYNC_VALIDATORS doesn't use Observable directly, it doesn't subscribe to them but converts them to Promises, in any case, NG_ASYNC_VALIDATORS still accepts Observables. Look at line #104 in validators.ts.
Thanks to @przemcio for the observation.
Not yet implemented / In conversation
- ObserveChild which would return an
EventEmitter. - ObserveChildren Update
Note
They are working on bundle RxJS with the bare operators, see issue #5288. The idea is to distribute angular2 with the minimal required operators and make the user to provide the rest of them.
Note update
Like I was told here and here (I had a problem with importing Subject) they're working on removing completely Subject, so from core we would be able to import only Observable, everything else should be provided by the developer.
PS
I can't think of any other, if I remember of something else I'll update the answer.
来源:https://stackoverflow.com/questions/33860374/what-functionalities-that-rxjs-provide-for-angular2