<commit_before>'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var React = require('react');
var ReactDom = require('react-dom');
var f1DOM = require('f1-dom');
var merge = require('deep-extend');

class ReactF1 extends React.Component {

  constructor(props) {
    super(props);

    this.hasMounted = false;
    this.f1 = null;

    this.state = {};
  }

  setupFromProps(props) {
    if (!this.f1) {
      this.initFromProps(props);
    } else {
      this.updateFromProps(props);
    }
  }

  initFromProps(props) {
    if (this.hasMounted && props.go && props.states && props.transitions) {

      var el = ReactDom.findDOMNode(this);
      var f1 = this.f1 = f1DOM({
        el: el,
        states: props.states,
        transitions: props.transitions,
        targets: props.targets,
        parsers: props.parsers
      });

      f1.on('state', this.handleState.bind(this));
      f1.on('update', this.handleUpdate.bind(this));
      this.updateListenersFromProps(props);

      this.setState({
        states: props.states
      });

      f1.init(props.go);
    }
  }

  updateFromProps(props) {
    var states;

    if (props.states) {

      merge(this.state.states, props.states);

      this.setState({
        states: this.state.states
      });

      // force an update to f1 since we received new props
      this.f1.update();
    }

    if (props.go) {
      if (this.f1) {
        this.f1.go(props.go, props.onComplete);
      }
    }
<commit_msg>Adding an ability to update the target after initialization<commit_after>'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var React = require('react');
var ReactDom = require('react-dom');
var f1DOM = require('f1-dom');
var merge = require('deep-extend');

class ReactF1 extends React.Component {

  constructor(props) {
    super(props);

    this.hasMounted = false;
    this.f1 = null;

    this.state = {};
  }

  setupFromProps(props) {
    if (!this.f1) {
      this.initFromProps(props);
    } else {
      this.updateFromProps(props);
    }
  }

  initFromProps(props) {
    if (this.hasMounted && props.go && props.states && props.transitions) {

      var el = ReactDom.findDOMNode(this);
      var f1 = this.f1 = f1DOM({
        el: el,
        states: props.states,
        transitions: props.transitions,
        targets: props.targets,
        parsers: props.parsers
      });

      f1.on('state', this.handleState.bind(this));
      f1.on('update', this.handleUpdate.bind(this));
      this.updateListenersFromProps(props);

      this.setState({
        states: props.states
      });

      f1.init(props.go);
    }
  }

  updateFromProps(props) {
    var states;

    if (props.states) {

      merge(this.state.states, props.states);

      this.setState({
        states: this.state.states
      });

      // force an update to f1 since we received new props
      this.f1.update();
    }

    if(props.targets){
      this.f1.targets(props.targets);
      // force an update to f1 since we received new props
      this.f1.update();
    }


    if (props.go) {
      if (this.f1) {
        this.f1.go(props.go, props.onComplete);
      }
    }

{'fraction_non_alphanumeric': 0.14500836586726157, 'fraction_numerical': 0.009760178471834913, 'mean_word_length': 2.5029296875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7167670', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1157, 'n_words': 255}