import * as React from "react";
import { useSessionContext } from "./SessionContext";
export const useArticleSubscription = (comId) => {
    const { session } = useSessionContext();
    const [article, setArticle] = React.useState(() => comId === undefined ? undefined : session.getArticleByComId(comId));
    React.useEffect(() => {
        const update = (article) => {
            if (article.comId === comId) {
                setArticle(session.getArticleByComId(comId));
            }
        };
        const subscription = session.subscribe({
            ItemCreated: update,
            ItemConfigured: update,
            ItemRemoved: update,
            ItemGfxInserted: update,
        });
        return () => subscription.destroy();
    }, [comId]);
    return article;
};
const ArticleSubscription = props => {
    const article = useArticleSubscription(props.comId);
    return props.children({ article });
};
ArticleSubscription.displayName = "ArticleSubscription";
export default ArticleSubscription;
