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

var Surface = Substance.Surface;

// Container Node
// ----------------
//
// Represents a flat collection of nodes

var ContainerComponent = React.createClass({
  displayName: "ContainerComponent",

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

  childContextTypes: {
    surface: React.PropTypes.object,
    getHighlightedNodes: React.PropTypes.func
  },

  getInitialState: function() {
    return {
      surface: new Surface(new Surface.FullfledgedEditor(this.props.node))
    };
  },

  getHighlightedNodes: function() {
    return this.props.writerCtrl.getHighlightedNodes();
  },

  getChildContext: function() {
    return {
      surface: this.state.surface,
      getHighlightedNodes: this.getHighlightedNodes
    };
  },

  render: function() {
    var containerNode = this.props.node;
    var doc = this.props.doc;
    var writerCtrl = this.props.writerCtrl;
    var componentFactory = this.context.componentFactory;
    var components = containerNode.nodes.map(function(nodeId) {
      var node = doc.get(nodeId);
      var ComponentClass = componentFactory.get(node.type);
      if (!ComponentClass) {
        throw new Error('Could not resolve a component for type: ' + node.type);
      }
      return $$(ComponentClass, {
        key: node.id,
        doc: doc,
        node: node,
        // TODO: we should use DI instead of coupling to the writer
        writerCtrl: writerCtrl
      });
    });

    return $$("div", {className: "container-node " + this.props.node.id, contentEditable: true },
      $$('div', {className: "nodes"}, components)
    );
  },

  componentDidMount: function() {
    var surface = this.state.surface;
    this.props.writerCtrl.registerSurface(surface, "content");
    surface.attach(this.getDOMNode());
  },

  componentWillUnmount: function() {
    var surface = this.state.surface;
    this.props.writerCtrl.unregisterSurface(surface);
    surface.detach();
  },

});

module.exports = ContainerComponent;<commit_msg>Rerender ContainerComponent when nodes change.<commit_after>var Substance = require('substance');
var $$ = React.createElement;

var Surface = Substance.Surface;

// Container Node
// ----------------
//
// Represents a flat collection of nodes

var ContainerComponent = React.createClass({
  displayName: "ContainerComponent",

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

  childContextTypes: {
    surface: React.PropTypes.object,
    getHighlightedNodes: React.PropTypes.func
  },

  getInitialState: function() {
    return {
      surface: new Surface(new Surface.FullfledgedEditor(this.props.doc))
    };
  },

  getHighlightedNodes: function() {
    return this.props.writerCtrl.getHighlightedNodes();
  },

  getChildContext: function() {
    return {
      surface: this.state.surface,
      getHighlightedNodes: this.getHighlightedNodes
    };
  },

  render: function() {
    var containerNode = this.props.node;
    var doc = this.props.doc;
    var writerCtrl = this.props.writerCtrl;
    var componentFactory = this.context.componentFactory;
    var components = containerNode.nodes.map(function(nodeId) {
      var node = doc.get(nodeId);
      var ComponentClass = componentFactory.get(node.type);
      if (!ComponentClass) {
        throw new Error('Could not resolve a component for type: ' + node.type);
      }
      return $$(ComponentClass, {
        key: node.id,
        doc: doc,
        node: node,
        // TODO: we should use DI instead of coupling to the writer
        writerCtrl: writerCtrl
      });
    });

    return $$("div", {
        className: "container-node " + this.props.node.id,
        contentEditable: true,
        "data-id": this.props.node.id
      },
      $$('div', {className: "nodes"}, components)
    );
  },

  componentDidMount: function() {
    var surface = this.state.surface;
    this.props.doc.getEventProxy('path').add([this.props.node.id, 'nodes'], this, this.containerDidChange);
    this.props.writerCtrl.registerSurface(surface, "content");
    surface.attach(this.getDOMNode());
  },

  componentWillUnmount: function() {
    var surface = this.state.surface;
    this.props.doc.getEventProxy('path').remove([this.props.node.id, 'nodes'], this);
    this.props.writerCtrl.unregisterSurface(surface);
    surface.detach();
  },

  containerDidChange: function() {
    var self = this;
    this.forceUpdate();
    // update the surface afterwards so that it can re-analyze the component layout
    setTimeout(function() {
      self.state.surface.update();
    });
  },

});

module.exports = ContainerComponent;
{'fraction_non_alphanumeric': 0.13289389751222624, 'fraction_numerical': 0.0, 'mean_word_length': 3.093994778067885, 'pattern_counts': {'":': 1, '<': 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': '1788958', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1335, 'n_words': 294}