import React, { useEffect } from "react";
import { useSelector } from "react-redux";
function MessageListener() {
  const messageEvents = useSelector(state => {
    var _state$app$activeTopi;
    return (_state$app$activeTopi = state.app.activeTopic) === null || _state$app$activeTopi === void 0 ? void 0 : _state$app$activeTopi.messageEvents;
  });
  useEffect(() => {
    const abrtCtrl = new AbortController();
    const {
      signal
    } = abrtCtrl;
    (messageEvents || []).forEach(messageEvent => {
      const callback = evt => {
        if (evt.type === messageEvent.eventType || evt.data === messageEvent.eventType) {
          messageEvent.callback(evt);
        }
      };
      window.addEventListener("message", callback, {
        signal
      });
    });
    return () => {
      abrtCtrl.abort();
    };
  }, [messageEvents]);
  return null;
}
export default /*#__PURE__*/React.memo(MessageListener);
//# sourceMappingURL=MessageListener.js.map