UNPKG

@lifaon/rx-js-light

Version:

Blazing fast Observables

31 lines (30 loc) 678 B
import {freeze} from "../../../../../misc/helpers/freeze.mjs"; export function createReplayLastSource(source, options) { let currentValue; let initialized; if (options === void 0 || !(('initialValue' in options))) { initialized = false; } else { initialized = true; currentValue = options.initialValue; } const emit = value => { initialized = true; currentValue = value; source.emit(value); }; const subscribe = emit => { if (initialized) { emit(currentValue); } return source.subscribe(emit); }; return freeze({ ...source, getValue: () => { return currentValue; }, emit, subscribe }); }