Installation and Setup
TH Rxjs lib can be consumed in many different ways, namely , CommonJS
and as ES5/CDN
.
import Rx from 'rxjs/Rx';
This statement import Rx from 'rxjs/Rx'
utilizes the entire library. It is great for testing out various features but once hitting production this is a bad idea as Rxjs is quite a heave library. In a more realistic scenario you would want to use the alternate approach below that only imports the operators that you actually use :
Setup is different though
Below is yet again showcasing the greedy import that is great for testing but bad for production
let Observable = require('rxjs/Observable').Observable;
require('rxjs/add/observable/of');
require('rxjs/add/operator/map');
As you can see require('rxjs/Observable')
just gives us the Rx object and we need to dig one level down to find the Observable.
Notice also we just to get the operator we want to import for our app.
Notice however this will give you the full lib. As you are requiring it externally it won’t affect your bundle size though.