"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useObservable = exports.useReplaySubject = void 0;
const rxjs_1 = require("rxjs");
const react_1 = require("react");
// emit value each time it changes by reference. it replays the last value at subscribe time.
function useReplaySubject(value) {
    const [subject] = (0, react_1.useState)(() => new rxjs_1.ReplaySubject());
    (0, react_1.useEffect)(() => {
        subject.next(value);
    }, [subject, value]);
    (0, react_1.useEffect)(() => {
        return () => {
            subject.complete();
        };
    }, [subject]);
    return subject;
}
exports.useReplaySubject = useReplaySubject;
function useObservable(observable, initialValue) {
    const [value, update] = (0, react_1.useState)(initialValue || undefined);
    (0, react_1.useEffect)(() => {
        const s = observable.subscribe(update);
        return () => s.unsubscribe();
    }, [observable]);
    return value;
}
exports.useObservable = useObservable;
//# sourceMappingURL=observable.js.map