Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = [1, 2, 3, 4, 5, 6];
- ogObservable = rxjs.from(data);
- filteredObservable = new rxjs.Subject();
- isError = (val) => val == 3;
- let lastStoredValue = null;
- //sub so we can show the values from the result observable
- filteredObservable.subscribe(x => console.log(`Got value from resulting observable: ${x}`));
- ogObservable.subscribe(x => {
- //console.log(`Got ${x}, last value was ${lastStoredValue}`);
- // seed with the first value
- if (lastStoredValue === null) {
- lastStoredValue = x;
- return;
- }
- // if x is an error state, we need to reset the last stored value
- if (isError(x)) {
- //console.log("error");
- lastStoredValue = null
- }
- // if x is not an error state, then send the last stored value to the subject
- else {
- //console.log(`Not an error, pushing ${lastStoredValue}`);
- filteredObservable.next(lastStoredValue);
- lastStoredValue = x;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement