<commit_before>const axios = require('axios')
const createHistory = require('history').createBrowserHistory
const queryString = require('qs')

const history = createHistory()

history.listen((location, action) => {
  if (action === 'POP') {
    if (location.state) {
      XHR.injectResponseInHtml(location.state.data)
    } else if (window.location.pathname !== location.pathname && window.location.search !== location.search) {
      window.location.href = location.pathname + location.search
    }
  }
})

const XHR = {
  injectResponseInHtml (data) {
    const dataDocument = document.createRange().createContextualFragment(data)

    const xhrContainers = document.querySelectorAll('[data-xhr]')
    xhrContainers.forEach((xhrContainer) => {
      const xhrContainerId = xhrContainer.getAttribute('data-xhr')

      const newContent = dataDocument.querySelector(`[data-xhr="${xhrContainerId}"]`)
      if (newContent) {
        xhrContainer.outerHTML = newContent.outerHTML
      }
    })
  },

  updateOutlet (res, params) {
    this.injectResponseInHtml(res.data)

    if (params) {
      const url = `?${queryString.stringify(params)}`
      try {
        history.replace(url, { data: res.data })
      } catch (err) {
        // state was too large for browser to handle. Do full page load.
        window.location.assign(url)
      }
    }

    return res
  },

  request (url, params = {}) {
    if (params) {
      const url = `?${queryString.stringify(params)}`
      history.push(url)
    }

    return axios
      .get(`${url}?${queryString.stringify(params, { arrayFormat: 'repeat' })}`, {
        headers: { 'X-Requested-With': 'XMLHttpRequest' },
      })
      .then(res => this.updateOutlet(res, params))
  },
}

module.exports = XHR
<commit_msg>Swapping out a forEach loop for the for...in loop<commit_after>const axios = require('axios')
const createHistory = require('history').createBrowserHistory
const queryString = require('qs')

const history = createHistory()

history.listen((location, action) => {
  if (action === 'POP') {
    if (location.state) {
      XHR.injectResponseInHtml(location.state.data)
    } else if (window.location.pathname !== location.pathname && window.location.search !== location.search) {
      window.location.href = location.pathname + location.search
    }
  }
})

const XHR = {
  injectResponseInHtml (data) {
    const dataDocument = document.createRange().createContextualFragment(data)

    const xhrContainers = document.querySelectorAll('[data-xhr]')
    for (const prop in xhrContainers) {
      if (xhrContainers.hasOwnProperty(prop)) {
        const xhrContainer = xhrContainers[prop]
        const xhrContainerId = xhrContainer.getAttribute('data-xhr')
        const newContent = dataDocument.querySelector(`[data-xhr="${xhrContainerId}"]`)
        if (newContent) {
          xhrContainer.outerHTML = newContent.outerHTML
        }
      }
    }
  },

  updateOutlet (res, params) {
    this.injectResponseInHtml(res.data)

    if (params) {
      const url = `?${queryString.stringify(params)}`
      try {
        history.replace(url, { data: res.data })
      } catch (err) {
        // state was too large for browser to handle. Do full page load.
        window.location.assign(url)
      }
    }

    return res
  },

  request (url, params = {}) {
    if (params) {
      const url = `?${queryString.stringify(params)}`
      history.push(url)
    }

    return axios
      .get(`${url}?${queryString.stringify(params, { arrayFormat: 'repeat' })}`, {
        headers: { 'X-Requested-With': 'XMLHttpRequest' },
      })
      .then(res => this.updateOutlet(res, params))
  },
}

module.exports = XHR

{'fraction_non_alphanumeric': 0.14095238095238094, 'fraction_numerical': 0.0, 'mean_word_length': 3.093541202672606, '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': '3802995', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1119, 'n_words': 221}