javascript - Rx.js and application workflow -


i've got web application i'm using rx.js handling event streams. app uses rest api provided backend.

mostly make subscription api call , when request done render results , reset other controls states (hide progress elements , on).

some api calls can failed when auth token expired , have make user login again (show login popup or so).

i'm curious there way "restore" api call stream after successful login? user has not provide additional actions server response.

primitive example of current workflow:

var apicallstream = $.ajaxasobservable(params): apicallstream.subscribe(   result => renderresult(result),   err => handleerror(err));  function handleerror(err) {   if (err.xhr.error === 401) {     loginpopup();   } else {     errorpopup(err);   } } 

here some (very rough pseudo-code), retrywhen:

// use rx.dom.get observable ajax var source = rx.dom.get('/some/end/point')   .retrywhen(function(errors) {     // retrywhen: errors stream of errors     // whatever observable return, when emits,     // observable you're operating on retried. (the entire thing)     return errors.filter(function(e) { return e.status === 401; })        // if status 401, tell user login        .flatmaplatest(function() { return douserlogin; });   });  // contrived observable shows form , // return stream of successful logins var douserlogin = observable.create(function(observer) {   // show form   var form = $('.my-form').show();   // when submit fired on said form...   return rx.observable.fromevent(form, 'submit')      // send login on ajax     .flatmap(e => rx.dom.post('some/url/login', form.serialize())) }); 

hopefully gives start with.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -