<commit_before>/** @jsx React.DOM */

var ClientID = require('./ClientID');
var StyleConverter = require('./StyleConverter');
var _ = require('lodash');
var autoprefixer = require('autoprefixer');

var autoprefixerInstance = autoprefixer();
var countByStyleName = {};

function StyleMixin(stylesByName) {
  var classesByStyleName;
  var hasInjectedStyles = false;

  return {
    componentWillMount() {
      if (hasInjectedStyles) {
        this.styles = classesByStyleName;
        return;
      }

      var processedStylesByName = _.mapValues(stylesByName, processStyle);
      var classNameBase = this.constructor.displayName;
      if (countByStyleName[classNameBase]) {
        classNameBase += '-' + countByStyleName[classNameBase];
      }
      countByStyleName[classNameBase] =
        (countByStyleName[classNameBase] || 0) + 1;

      var cssRules = [];
      classesByStyleName = _.mapValues(processedStylesByName, (style, name) => {
        var className = classNameBase + '_' + name;
        var css = StyleConverter.toCssString(className, style);
        css = autoprefixerInstance.process(css);
        cssRules.push(css);
        return className;
      });
      this.styles = classesByStyleName;

      var tag = document.createElement('style');
      tag.innerHTML = cssRules.join('\n');
      document.getElementsByTagName('head')[0].appendChild(tag);

      hasInjectedStyles = true;
    },
  };
}

function processStyle(style) {
  if (Array.isArray(style)) {
    var processedStyles = style.map(processStyle);
    return Object.assign.apply(null, [{}].concat(processedStyles));
  }

  return _.mapValues(style, (value, key) => {
    if (value instanceof Color) {
      return value.toString();
    }

    // nested, like :hover or :after
    if (_.isObject(value)) {
      return processStyle(value);
    }

    return value;
  });
}

module.exports = StyleMixin;<commit_msg>Remove unused styles from page.<commit_after>/** @jsx React.DOM */

var ClientID = require('./ClientID');
var StyleConverter = require('./StyleConverter');
var _ = require('lodash');
var autoprefixer = require('autoprefixer');

var autoprefixerInstance = autoprefixer();
var countByStyleName = {};

function StyleMixin(stylesByName) {
  var tag;
  var classesByStyleName;
  var mountedComponentCount = 0;
  var cleanupStyleTag = function() {
    mountedComponentCount--;
    if (mountedComponentCount === 0) {
      tag.parentNode.removeChild(tag);
    }
  };

  return {
    componentWillMount() {
      mountedComponentCount++;

      if (mountedComponentCount > 1) {
        this.styles = classesByStyleName;
        return;
      }

      var processedStylesByName = _.mapValues(stylesByName, processStyle);
      var classNameBase = this.constructor.displayName;
      if (countByStyleName[classNameBase]) {
        classNameBase += '-' + countByStyleName[classNameBase];
      }
      countByStyleName[classNameBase] =
        (countByStyleName[classNameBase] || 0) + 1;

      var cssRules = [];
      classesByStyleName = _.mapValues(processedStylesByName, (style, name) => {
        var className = classNameBase + '_' + name;
        var css = StyleConverter.toCssString(className, style);
        css = autoprefixerInstance.process(css);
        cssRules.push(css);
        return className;
      });
      this.styles = classesByStyleName;

      tag = document.createElement('style');
      tag.innerHTML = cssRules.join('\n');
      document.getElementsByTagName('head')[0].appendChild(tag);
    },

    componentWillUnmount() {
      setTimeout(cleanupStyleTag, 100);
    },
  };
}

function processStyle(style) {
  if (Array.isArray(style)) {
    var processedStyles = style.map(processStyle);
    return Object.assign.apply(null, [{}].concat(processedStyles));
  }

  return _.mapValues(style, (value, key) => {
    if (value instanceof Color) {
      return value.toString();
    }

    // nested, like :hover or :after
    if (_.isObject(value)) {
      return processStyle(value);
    }

    return value;
  });
}

module.exports = StyleMixin;
{'fraction_non_alphanumeric': 0.12844488188976377, 'fraction_numerical': 0.002952755905511811, 'mean_word_length': 3.238790406673618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3997213', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1192, 'n_words': 235}