I think I have the base concept, but there are some obscurities
So in general this is how I use an Observable
:
observable.subscribe(x => {
})
If I want to filter data I can use this:
import { first, last, map, reduce, find, skipWhile } from 'rxjs/operators';
observable.pipe(
map(x => {return x}),
first()
).subscribe(x => {
})
I can also do this:
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/first';
observable.map(x => {return x}).first().subscribe(x => {
})
So my questions are:
- What is the difference?
- If there is no difference, why the function
pipe
exists?
- Why those functions need different imports?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…