SHARE
TWEET

Untitled

a guest Oct 15th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data = [1, 2, 3, 4, 5, 6];
  2. ogObservable = rxjs.from(data);
  3. filteredObservable = new rxjs.Subject();
  4.  
  5. isError = (val) => val == 3;
  6.  
  7. let lastStoredValue = null;
  8. //sub so we can show the values from the result observable
  9. filteredObservable.subscribe(x => console.log(`Got value from resulting observable: ${x}`));
  10.  
  11. ogObservable.subscribe(x => {
  12.     //console.log(`Got ${x}, last value was ${lastStoredValue}`);
  13.     // seed with the first value
  14.     if (lastStoredValue === null) {
  15.     lastStoredValue = x;
  16.     return;
  17.   }
  18.   // if x is an error state, we need to reset the last stored value
  19.   if (isError(x)) {
  20.     //console.log("error");
  21.     lastStoredValue = null
  22.   }
  23.   // if x is not an error state, then send the last stored value to the subject
  24.     else {
  25.     //console.log(`Not an error, pushing ${lastStoredValue}`);
  26.     filteredObservable.next(lastStoredValue);
  27.     lastStoredValue = x;
  28.   }
  29. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top