"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObserveMultiState = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
/**

 <ObserveMultiState
 listenTo={[anobject, anobject]}
 control={() => {
        return (

        );
    }}
 />
 **/
class ObserveMultiState extends react_1.default.Component {
    render() {
        return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: this.props.control() }, DataUtilities_1.DataUtilities.generateUniqueId());
    }
    componentDidUpdate(prevProps) {
        for (let obj of this.props.listenTo) {
            if (obj && !prevProps.listenTo.includes(obj)) {
                StateManager_1.StateManager.addObserver(obj, this);
            }
        }
        for (let obj of prevProps.listenTo) {
            if (obj && !this.props.listenTo.includes(obj)) {
                StateManager_1.StateManager.removeObserver(obj, this);
            }
        }
    }
    componentDidMount() {
        if (this.props.listenTo) {
            for (let l of this.props.listenTo) {
                if (l)
                    StateManager_1.StateManager.addObserver(l, this);
            }
        }
    }
    componentWillUnmount() {
        if (this.props.listenTo) {
            for (let l of this.props.listenTo) {
                if (l)
                    StateManager_1.StateManager.removeObserver(l, this);
            }
        }
        if (this.props.onWillUnmount) {
            this.props.onWillUnmount();
        }
    }
}
exports.ObserveMultiState = ObserveMultiState;
//# sourceMappingURL=ObserveMultiState.js.map