Created
March 12, 2016 12:24
-
-
Save MichalZalecki/d78c52ec55d7ec7b53f7 to your computer and use it in GitHub Desktop.
How to import RxJS 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import all | |
import Rx from "rxjs/Rx"; | |
Rx.Observable | |
.interval(200) | |
.take(9) | |
.map(x => x + "!!!") | |
.bufferCount(2) | |
.subscribe(::console.log); | |
// Add operators (my favourite) | |
import {Observable} from "rxjs/Observable"; | |
import "rxjs/add/observable/interval"; | |
import "rxjs/add/operator/take"; | |
import "rxjs/add/operator/map"; | |
import "rxjs/add/operator/bufferCount" | |
Observable | |
.interval(200) | |
.take(9) | |
.map(x => x + "!!!") | |
.bufferCount(2) | |
.subscribe(::console.log); | |
// JavaScript ES7 Function Bind Syntax | |
import {Observable} from "rxjs/Observable"; | |
import "rxjs/add/observable/interval"; | |
import {take} from "rxjs/operator/take"; | |
import {map} from "rxjs/operator/map"; | |
import {bufferCount} from "rxjs/operator/bufferCount" | |
Observable | |
.interval(200) | |
::take(9) | |
::map(x => x + "!!!") | |
::bufferCount(2) | |
.subscribe(::console.log); |
We should all be moving to this https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md for all the reasons listed in the article under 'Why?'
@briancodes
As per your suggestion,
app.module.ts
import './rxjs-operators';
You won't need to import anywhere else in your application now
Following your suggestion, If now I am using 'map' operator in some component.ts file, it asks for importing library for map operator.
Other point is that, If I am using on map and do operator in my application using import 'rxjs/add/operator/map',
it includes the whole operator library in the build.
Thank you for your help!
Can you update this for RXjs 6 ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@briancodes Thanks, you have the best solution.