<commit_before>import React from 'react';
import Rx from 'rx-lite';
import isFunction from 'lodash.isfunction';

class SubscriberWrapper extends React.Component {
  constructor(props) {
    super(props);

    this.state = {};
    this.disposable = new Rx.CompositeDisposable();
  }

  subscribeOnNext(observable) {
    this.disposable.add(
      observable.subscribeOnNext((stateChanges) => {
        if (stateChanges) {
          this.setState(stateChanges);
        }
      })
    );
  }

  componentDidMount() {
    let { observables: resolvedObservables, forwardedProps } = this.props;
    if (isFunction(resolvedObservables)) {
      resolvedObservables = resolvedObservables(forwardedProps);
    }

    resolvedObservables.forEach(observable => {
      this.subscribeOnNext(observable);
    });
  }

  componentWillUnmount() {
    this.disposable.dispose();
  }

  render() {
    const { component: Component, forwardedProps } = this.props;
    return (
      <Component { ...forwardedProps } { ...this.state } />
    );
  }
}

export default function subscriber(observables) {
  return (Component) => (props) => (
    <SubscriberWrapper forwardedProps={ props } observables={ observables } component={ Component } />
  );
}<commit_msg>Reload observables when receiving new props<commit_after>import React from 'react';
import Rx from 'rx-lite';
import isFunction from 'lodash.isfunction';

class SubscriberWrapper extends React.Component {
  constructor(props) {
    super(props);

    this.state = {};
  }

  subscribeOnNext(observable) {
    this.disposable.add(
      observable.subscribeOnNext((stateChanges) => {
        if (stateChanges) {
          this.setState(stateChanges);
        }
      })
    );
  }

  subscribeToObservables(props) {
    if (this.disposable) {
      this.disposable.dispose();
    }

    this.disposable = new Rx.CompositeDisposable();

    let { observables: resolvedObservables, forwardedProps } = props;
    if (isFunction(resolvedObservables)) {
      resolvedObservables = resolvedObservables(forwardedProps);
    }

    resolvedObservables.forEach(observable => {
      this.subscribeOnNext(observable);
    });
  }

  componentDidMount() {
    this.subscribeToObservables(this.props);
  }

  componentWillReceiveProps(nextProps) {
    this.subscribeToObservables(nextProps);
  }

  componentWillUnmount() {
    this.disposable.dispose();
  }

  render() {
    const { component: Component, forwardedProps } = this.props;
    return (
      <Component { ...forwardedProps } { ...this.state } />
    );
  }
}

export default function subscriber(observables) {
  return (Component) => (props) => (
    <SubscriberWrapper forwardedProps={ props } observables={ observables } component={ Component } />
  );
}
{'fraction_non_alphanumeric': 0.12431842966194111, 'fraction_numerical': 0.0, 'mean_word_length': 3.3406940063091484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '6665295', 'n_tokens_mistral': 829, 'n_tokens_neox': 776, 'n_words': 144}