Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJS flatMapLatest is not a function

Using RxJs I am trying to reproduce a demo. But i am not getting any result. Instead getting error as : distinct.flatMapLatest is not a function

what is wrong i did here? do i required to add any library here?

here is my try: but look in to demo to get real issue what is face.

$(document).ready(function(){

var $input = $('#input'),
    $results = $('#results');

var keyups = Rx.Observable.fromEvent($input, 'keyup')
    .map(e => e.target.value)
    .filter(text => text.length > 2);

var throttled = keyups.throttle(500);

var distinct = throttled.distinctUntilChanged();

function searchWikipedia (term) {
    return $.ajax({
        url: 'http://en.wikipedia.org/w/api.php',
        dataType: 'jsonp',
        data: {
            action: 'opensearch',
            format: 'json',
            search: term
        } 
    }).promise();

}


var suggestions = distinct.flatMapLatest(searchWikipedia);

suggestions.subscribe(data => {
    var res = data[1];
    /* Do something with the data like binding */
    $results.empty();

    $.each(res, (_, value) => $('<li>' + value + '</li>').appendTo($results));
}, error => {
    /* handle any errors */
    $results.empty();

    $('<li>Error: ' + error + '</li>').appendTo($results);

});

})

Live Demo

like image 265
user2024080 Avatar asked Mar 09 '16 05:03

user2024080


1 Answers

In RxJS 5, flatMapLatest has been renamed to switchMap.

var suggestions = distinct.switchMap(searchWikipedia);
like image 134
m59 Avatar answered Sep 20 '22 19:09

m59