"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var SessionContext_1 = require("./SessionContext");
exports.useArticleSubscription = function (comId) {
    var session = SessionContext_1.useSessionContext().session;
    var _a = tslib_1.__read(React.useState(function () {
        return comId === undefined ? undefined : session.getArticleByComId(comId);
    }), 2), article = _a[0], setArticle = _a[1];
    React.useEffect(function () {
        var update = function (article) {
            if (article.comId === comId) {
                setArticle(session.getArticleByComId(comId));
            }
        };
        var subscription = session.subscribe({
            ItemCreated: update,
            ItemConfigured: update,
            ItemRemoved: update,
            ItemGfxInserted: update,
        });
        return function () { return subscription.destroy(); };
    }, [comId]);
    return article;
};
var ArticleSubscription = function (props) {
    var article = exports.useArticleSubscription(props.comId);
    return props.children({ article: article });
};
ArticleSubscription.displayName = "ArticleSubscription";
exports.default = ArticleSubscription;
