<commit_before>import React from "react";
import cloneWithProps from "react/lib/cloneWithProps";

import ResolverError from "./ResolverError";

const { Children } = React;

class Container extends React.Component {
  constructor(props, context) {
    super(props, context);

    this.children = [];

    this.id = this.getId();
    this.state = this.getResolver().getContainerState(this);
  }

  componentWillMount() {
    this.resolve();
  }

  componentWillUnmount() {
    this.getResolver().clearContainerState(this);
  }

  componentWillReceiveProps() {
    this.getResolver().clearContainerState(this);

    this.resolve();
  }

  getId() {
    const parent = this.context.parent;

    if (!parent) {
      return ".0";
    }

    const id = `${parent.id}.${parent.children.length}`;

    parent.children.push(this);

    return id;
  }

  getChildContext() {
    const parent = this;
    const resolver = this.getResolver();

    return {
      parent,
      resolver
    };
  }

  getResolver() {
    const resolver = this.props.resolver || this.context.resolver;

    if (!resolver) {
      throw new ReferenceError("Resolver is not defined in either `context` or `props`.  (Perhaps missing a root <Container resolver={new Resolver()} />?)");
    }

    return resolver;
  }

  shouldComponentUpdate(props, state) {
    return state.fulfilled;
  }

  render() {
    if (!this.state.fulfilled) {
      return false;
    }

    if (this.props.component) {
      return (
        <this.props.component {...this.state.values} />
      );
    }

    if (this.props.element) {
      return cloneWithProps(this.props.element);
    }

    if (this.props.children) {
      if (Children.count(this.props.children) === 1) {
        return cloneWithProps(Children.only(this.props.children));
      }<commit_msg>Container will optionally errorRender and waitRender<commit_after>import React from "react";
import cloneWithProps from "react/lib/cloneWithProps";

import ResolverError from "./ResolverError";

const { Children } = React;

class Container extends React.Component {
  constructor(props, context) {
    super(props, context);

    this.children = [];

    this.id = this.getId();
    this.state = this.getResolver().getContainerState(this);
  }

  componentWillMount() {
    this.resolve();
  }

  componentWillUnmount() {
    this.getResolver().clearContainerState(this);
  }

  componentWillReceiveProps() {
    this.getResolver().clearContainerState(this);

    this.resolve();
  }

  getId() {
    const parent = this.context.parent;

    if (!parent) {
      return ".0";
    }

    const id = `${parent.id}.${parent.children.length}`;

    parent.children.push(this);

    return id;
  }

  getChildContext() {
    const parent = this;
    const resolver = this.getResolver();

    return {
      parent,
      resolver
    };
  }

  getResolver() {
    const resolver = this.props.resolver || this.context.resolver;

    if (!resolver) {
      throw new ReferenceError("Resolver is not defined in either `context` or `props`.  (Perhaps missing a root <Container resolver={new Resolver()} />?)");
    }

    return resolver;
  }

  shouldComponentUpdate(props, state) {
    return state.fulfilled || state.error;
  }

  render() {
    if(this.state.error)
    {
      if(this.props.component && this.props.component.errorRender)
      {
        return this.props.component.errorRender(this.state);
      }
      else
      {
        return false;
      }
    }
    if (!this.state.fulfilled) {
       if(this.props.component && this.props.component.waitRender)
        {
          return this.props.component.waitRender(this.state);
        }
        else
        {
          return false;
        }
    }

    if (this.props.component) {
      return (
        <this.props.component {...this.state.values} />
      );
    }

    if (this.props.element) {
      return cloneWithProps(this.props.element);
    }

    if (this.props.children) {
      if (Children.count(this.props.children) === 1) {
        return cloneWithProps(Children.only(this.props.children));
      }
{'fraction_non_alphanumeric': 0.13516160626836435, 'fraction_numerical': 0.0009794319294809011, 'mean_word_length': 2.624667258207631, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4071499', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1217, 'n_words': 241}