{"size": 1871, "ext": "js", "max_stars_repo_path": "src/framework/components/DemoAppConfig/DemoAppConfig.js", "max_stars_repo_name": "webcodesk/react-app-framework-demo", "max_stars_repo_stars_event_min_datetime": "2020-09-15T20:31:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T20:31:21.000Z", "max_issues_repo_path": "src/framework/components/DemoAppConfig/DemoAppConfig.js", "max_issues_repo_name": "ipselon/wcd-tailwind", "max_issues_repo_issues_event_min_datetime": "2021-05-11T03:57:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T05:15:33.000Z", "max_forks_repo_path": "src/framework/components/DemoAppConfig/DemoAppConfig.js", "max_forks_repo_name": "webcodesk/react-app-framework-demo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 27.5147058824, "max_line_length": 75, "alphanum_fraction": 0.5382148584}
import React from 'react';
import { get } from './appDemoRestClient';
const constants = require('../../commons/constants');

class DemoAppConfig extends React.Component {

  componentDidMount () {
    window.addEventListener("message", this.handleReceiveMessage, false);
  }

  componentWillUnmount () {
    window.removeEventListener("message", this.handleReceiveMessage);
  }

  handleReceiveMessage(event) {
    const {data: message} = event;
    if (message) {
      const {type} = message;
      if (type === constants.WEBCODESK_MESSAGE_GET_DECLARATIONS_WITH_ETC) {
        const result = {};
        get('/etcFiles.json')
          .then(data => {
            result.etcFiles = data;
            return get('/declarationFiles.json');
          })
          .then(data => {
            result.declarationFiles = data;
            window.parent.postMessage({
              type: constants.FRAMEWORK_MESSAGE_DECLARATIONS_WITH_ETC,
              payload: result,
            }, '*');
          })
          .catch(error => {
            window.parent.postMessage({
              type: 'error',
              payload: error.message,
            }, '*');
            console.error(error);
          });
      } else if (type === constants.WEBCODESK_MESSAGE_GET_DECLARATIONS) {
        const result = {};
        get('/declarationFiles.json')
          .then(data => {
            result.declarationFiles = data;
            window.parent.postMessage({
              type: constants.FRAMEWORK_MESSAGE_DECLARATIONS,
              payload: result,
            }, '*');
          })
          .catch(error => {
            window.parent.postMessage({
              type: 'error',
              payload: error.message,
            }, '*');
            console.error(error);
          });
      }
    }
  }


  render () {
    return null;
  }
}

export default DemoAppConfig;
