import { __decorate, __metadata } from "tslib";
import React from "react";
import { AutoBind } from "../../Common/AutoBind";
import { StateManager } from "./StateManager";
import { DataUtilities } from "../../Common/DataUtilities";
/**
 <ObserveState
 listenTo={anobject}
 control={() => {
        return (

        );
    }}
 />


 **/
export class ObserveState extends React.Component {
    render() {
        return this.props.control();
    }
    componentDidMount() {
        if (this.props.listenTo)
            StateManager.addObserver(this.props.listenTo, this, this.props.properties || []);
    }
    componentDidUpdate(prevProps) {
        if (prevProps.listenTo !== this.props.listenTo) {
            if (prevProps.listenTo)
                StateManager.removeObserver(prevProps.listenTo, this);
            if (this.props.listenTo)
                StateManager.addObserver(this.props.listenTo, this, this.props.properties || []);
        }
    }
    componentWillUnmount() {
        if (this.props.listenTo)
            StateManager.removeObserver(this.props.listenTo, this);
        if (this.props.onWillUnmount) {
            this.props.onWillUnmount();
        }
    }
    update() {
        this.setState({ key: DataUtilities.generateUniqueId() });
        this.forceUpdate();
    }
}
__decorate([
    AutoBind,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ObserveState.prototype, "update", null);
//# sourceMappingURL=ObserveState.js.map