<commit_before>var Substance = require("substance");
var $$ = React.createElement;

// Entity types
var Prison = require("./entity_types/prison");
var Toponym = require("./entity_types/toponym");
var Person = require("./entity_types/person");
var Definition = require("./entity_types/definition");

var _ = require("substance/helpers");

var ShowEntityReferencePanel = React.createClass({
  displayName: "Entity",

  contextTypes: {
    backend: React.PropTypes.object.isRequired
  },

  // Data loading methods
  // ------------

  loadEntity: function() {
    var doc = this.props.writerCtrl.doc;
    var self = this;
    var entityRef = doc.get(this.props.entityReferenceId);

    var backend = this.context.backend;

    backend.getEntities([entityRef.target], function(err, entities) {
      // Finished simulated loading of entities
      self.setState({
        entity: entities[0]
      });
    }.bind(this));
  },

  // State relevant things
  // ------------

  getInitialState: function() {
    return {
      entity: null
    };
  },

  // Events
  // ------------

  componentDidMount: function() {
    this.loadEntity();
  },

  componentWillReceiveProps: function() {
    this.loadEntity();
  },
<commit_msg>Don't use old state on state transition.<commit_after>var Substance = require("substance");
var $$ = React.createElement;

// Entity types
var Prison = require("./entity_types/prison");
var Toponym = require("./entity_types/toponym");
var Person = require("./entity_types/person");
var Definition = require("./entity_types/definition");

var _ = require("substance/helpers");

var ShowEntityReferencePanel = React.createClass({
  displayName: "Entity",

  contextTypes: {
    backend: React.PropTypes.object.isRequired
  },

  // Data loading methods
  // ------------

  loadEntity: function(props) {
    props = props || this.props;
    var doc = props.writerCtrl.doc;
    var self = this;
    var entityRef = doc.get(props.entityReferenceId);

    var backend = this.context.backend;

    backend.getEntities([entityRef.target], function(err, entities) {
      // Finished simulated loading of entities
      self.setState({
        entity: entities[0]
      });
    }.bind(this));
  },

  // State relevant things
  // ------------

  getInitialState: function() {
    return {
      entity: null
    };
  },

  // Events
  // ------------

  componentDidMount: function() {
    this.loadEntity();
  },

  componentWillReceiveProps: function(nextProps) {
    this.loadEntity(nextProps);
  },

{'fraction_non_alphanumeric': 0.16395394998015086, 'fraction_numerical': 0.0007939658594680428, 'mean_word_length': 2.853211009174312, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5829239', 'n_tokens_mistral': 739, 'n_tokens_neox': 715, 'n_words': 155}