none
[rxjs experimental]: switchlatest error

    Question

  • Hello I've a code like this

    var s = new Rx.AsyncSubject();
    ajax.success(function(data, status, xhr) {
    	s.onNext(data);
    	s.onCompleted();                
    });
    ajax.error = function (xhr, status, e) {
    	s.onError(e);
    };
    var latest = s.switchLatest();
    latest.subscribe(success, error);

    where 'ajax' is a simple jquery ajax object

    using switchLatest the code isn't working and breaks when 's.onCompleted()' is called ('subcribe is not defined').

    The code works as expected avoid using switchLatest().

    Any suggestions?


    Wednesday, February 29, 2012 11:16 AM

Answers

  • sorry, fixed.

    I've understand now that switchLatest works with observable sequences.

    fixed with 

    s.select(function(o) {
       return Rx.Observable.returnValue(o);
    }).switchLatest().subscribe(success, error);

    Wednesday, February 29, 2012 11:35 AM