import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { DataUtilities } from "../../Common/DataUtilities";
import { StateManager } from "./StateManager";
/**

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

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