<commit_before>var FreeStyle = require('free-style')
var insertStyles = require('insert-styles')
var window = require('global/window')

var styleInstancesById = {}
var DEFAULT_STYLE_ID = '__stylin__'

// Support multiple instances of the module in the same document.
module.exports = window.__stylin_data__ = window.__stylin_data__ || {
  STYLE_ID: DEFAULT_STYLE_ID,
  getStyles: getStyles,
  reset: reset,
  registerStyle: createStyleFunction('registerStyle', 1),
  registerKeyframes: createStyleFunction('registerKeyframes', 1),
  registerRule: createStyleFunction('registerRule', 2)
}

function getStyles (styleId) {
  var byId = styleInstancesById[styleId || DEFAULT_STYLE_ID]
  return byId && byId.Style ? byId.Style.getStyles() : ''
}

function reset () {
  styleInstancesById = {}
}

function createStyleFunction (methodName, arity) {
  return function styleFn () {
    var args = Array.prototype.slice.call(arguments)
    var opts = args.length > arity ? args.pop() : null
    var styleId = opts && opts.styleId ? opts.styleId : DEFAULT_STYLE_ID

    var byId = styleInstancesById[styleId] = styleInstancesById[styleId] || {
      Style: FreeStyle.create(),
      changeId: null
    }
    var Style = byId.Style
    var changeId = byId.changeId

    var result = Style[methodName].apply(Style, args)
    if (Style.changeId !== changeId) {
      insertStyles(Style.getStyles(), {id: styleId})
      changeId = Style.changeId
    }

    return result<commit_msg>fix(stylin): set changeId after changing<commit_after>var FreeStyle = require('free-style')
var insertStyles = require('insert-styles')
var window = require('global/window')

var styleInstancesById = {}
var DEFAULT_STYLE_ID = '__stylin__'

// Support multiple instances of the module in the same document.
module.exports = window.__stylin_data__ = window.__stylin_data__ || {
  STYLE_ID: DEFAULT_STYLE_ID,
  getStyles: getStyles,
  reset: reset,
  registerStyle: createStyleFunction('registerStyle', 1),
  registerKeyframes: createStyleFunction('registerKeyframes', 1),
  registerRule: createStyleFunction('registerRule', 2)
}

function getStyles (styleId) {
  var byId = styleInstancesById[styleId || DEFAULT_STYLE_ID]
  return byId && byId.Style ? byId.Style.getStyles() : ''
}

function reset () {
  styleInstancesById = {}
}

function createStyleFunction (methodName, arity) {
  return function styleFn () {
    var args = Array.prototype.slice.call(arguments)
    var opts = args.length > arity ? args.pop() : null
    var styleId = opts && opts.styleId ? opts.styleId : DEFAULT_STYLE_ID

    var byId = styleInstancesById[styleId] = styleInstancesById[styleId] || {
      Style: FreeStyle.create(),
      changeId: null
    }
    var Style = byId.Style
    var changeId = byId.changeId

    var result = Style[methodName].apply(Style, args)
    if (Style.changeId !== changeId) {
      insertStyles(Style.getStyles(), {id: styleId})
      byId.changeId = Style.changeId
    }

    return result
{'fraction_non_alphanumeric': 0.11320754716981132, 'fraction_numerical': 0.0020215633423180594, 'mean_word_length': 4.32078853046595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2834745', 'n_tokens_mistral': 927, 'n_tokens_neox': 925, 'n_words': 215}