xxxxxxxxxx
public class Switching {
public static void main(String[] args) throws InterruptedException {
Observable<String> source = Observable.just("John","Lily","Emma","Reyan","Darshin")
.concatMap(
s -> Observable.just(s)
.delay(
ThreadLocalRandom.current().nextInt(1000), TimeUnit.MILLISECONDS
)
);
Observable.interval(2, TimeUnit.SECONDS)
.switchMap( s -> source.doOnDispose(
() -> System.out.println("Disposing and starting again!")
)
)
.subscribe(System.out::println);
Thread.sleep(10000);
}
}
xxxxxxxxxx
this.mainForm.get("productCode").valueChanges
.pipe(
debounceTime(700),
switchMap(val => {
return this.queryDepositData();
})
)
.subscribe(data => {
this.product=data;
})
xxxxxxxxxx
ngOnInit() {
this.activatedRoute.paramMap
.pipe(
switchMap((params: Params) => {
return this.service.getProduct(params.get('id'))
}
))
.subscribe((product: Product) => this.product = product);
}
xxxxxxxxxx
this.mainForm.get("productCode").valueChanges
.pipe(
debounceTime(700)
)
.subscribe(val=> {
this.queryDepositData(val)
.subscribe(data => {
this.product=data;
})
})