"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSharedData = exports.setSharedData = void 0;
var react_1 = require("react");
var operators_1 = require("rxjs/operators");
var event_service_1 = require("../../services/event.service");
var PageObs = new event_service_1.Event({
    name: 'initial',
    data: {},
});
function setSharedData(name, data) {
    PageObs.set({
        name: name,
        data: data,
    });
}
exports.setSharedData = setSharedData;
function useSharedData(nameData, d) {
    var onChangeFn = react_1.useRef();
    function onChange(fn) {
        onChangeFn.current = fn;
    }
    function setValue(value, name) {
        setSharedData(name !== null && name !== void 0 ? name : nameData, value);
    }
    react_1.useEffect(function () {
        var obs = PageObs.observable.pipe(operators_1.skip(1)).subscribe(function (value) {
            if (nameData === value.name) {
                if (onChangeFn.current)
                    onChangeFn.current(value.data);
            }
        });
        return function () {
            obs.unsubscribe();
        };
    }, []);
    return [onChange, setValue];
}
exports.useSharedData = useSharedData;
//# sourceMappingURL=useSharedData.js.map