javascript - RxJS the switch function -


could please explain switch function in rxjs do?
read documentation not configure out, how works exactly.

if have observable stream of observable values, switch flatten nested observable single stream of observable values. feed values recent inner stream produced outer stream.

it easier example. have textbox controls data receive ajax query. lets call textbox page number. goal display results of ajax query page user types text box. can use switch construct observable stream of data:

function getpagedata(pagenumber) {    // return ajax query page    return $.ajax("/url?page=" + pagenumber)); }  var pagenumbervalue = // observable of page number values coming text box  // observable of observables of page data var datastreamofstreams = pagenumbervalue     .map(pagenumber => getpagedata(pagenumber);  // everytime change pages, "switch" new ajax call // , return results new call. var datastream = datastreamofstreams.switch(); 

i hope helps.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -