import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { PureComponent } from 'react';
export class WithProviders extends PureComponent {
  constructor(props) {
    super(props);
    _defineProperty(this, "handleProvider", (name, provider) => {
      this.setState(({
        providers
      }) => {
        return {
          providers: {
            ...providers,
            [name]: provider
          }
        };
      });
    });
    const _providers = {};
    this.props.providers.forEach(name => {
      _providers[name] = undefined;
    });
    this.state = {
      providers: _providers
    };
  }
  UNSAFE_componentWillMount() {
    const {
      providers,
      providerFactory
    } = this.props;
    providers.forEach(name => {
      providerFactory.subscribe(name, this.handleProvider);
    });
  }
  componentWillUnmount() {
    const {
      providers,
      providerFactory
    } = this.props;
    providers.forEach(name => {
      providerFactory.unsubscribe(name, this.handleProvider);
    });
  }
  render() {
    const {
      state,
      props
    } = this;
    const {
      renderNode
    } = props;
    return renderNode(state.providers);
  }
}
_defineProperty(WithProviders, "displayName", 'WithProviders');