UNPKG

@lifaon/rx-js-light

Version:

Blazing fast Observables

35 lines (34 loc) 884 B
import {asyncUnsubscribe} from "../../../../../../../../misc/helpers/async-unsubscribe.mjs"; export function notificationsToLastValueObservable(subscribe, onError) { return emit => { let running = true; const clear = () => { if (running) { running = false; asyncUnsubscribe(() => unsubscribe); } }; let lastValue; const unsubscribe = subscribe(notification => { switch (notification.name) { case 'next': lastValue = notification.value; break; case 'complete': emit(lastValue); clear(); break; case 'error': if (onError !== void 0) { onError(notification.value, value => { if (running) { emit(value); } }); } break; } }); return clear; }; }