<commit_before>import _ from 'lodash';
import npmData from '../services/downloads.js';
import {graph} from '../graph/graph.js';
import config from '../../config.js';

const palette = config.palette;

var {default: packageInput, emitter: packageEvents, packages, removePackage} = require('../packages/packages.js');

const injectDisqus = () => {
  var d = document, s = d.createElement('script');
  s.src = '//npmcharts.disqus.com/embed.js';
  s.setAttribute('data-timestamp', +new Date());
  (d.head || d.body).appendChild(s);

  var d = document, s = d.createElement('script');
  s.src = '//npmcharts.disqus.com/count.js';
  s.setAttribute('data-timestamp', +new Date());
  s.setAttribute('id', 'dsq-count-scr');
  (d.head || d.body).appendChild(s);
};

const resetDisqus = (packages) => {
  if (!packages) { return }
  const sortedPackages = packages.slice().sort();
  if (window.DISQUS && window.DISQUSWIDGETS) {
    window.DISQUS.reset({
      reload: true,
      config: function () {  
        this.page.identifier = sortedPackages.join(',')
        this.page.url = 'http://npmcharts.com/compare/' + sortedPackages.join(',');
      }
    })
    DISQUSWIDGETS.getCount({reset: true});
  } else {
    setTimeout(resetDisqus, 500)
  }
}

export default Vue.extend({
  route: {
    waitForData: true,
    data ({ to, next, redirect }) {
      const packageNames = (
        to.path === '/' || !to.params.packages
          ? _.sample(this.presetPackages)
          : to.params.packages.split(',').map(packageName => window.decodeURIComponent(packageName))
      );

      if (to.path === '/' || !to.params.packages) {
        document.title = "npmcharts - compare and graph npm packages";
      } else {
        document.title = "npmcharts - compare and graph npm packages - " + to.params.packages.split(',').join(', ');
      }

      ga('send', 'pageview');

      packageNames
      ? npmData.fetch(packageNames, false)
          .then(() => {
            const moduleData = npmData.modules.map(x => ({<commit_msg>🐛 don't wait for data to return to set isUsingPresetPackages<commit_after>import _ from 'lodash';
import npmData from '../services/downloads.js';
import {graph} from '../graph/graph.js';
import config from '../../config.js';

const palette = config.palette;

var {default: packageInput, emitter: packageEvents, packages, removePackage} = require('../packages/packages.js');

const injectDisqus = () => {
  var d = document, s = d.createElement('script');
  s.src = '//npmcharts.disqus.com/embed.js';
  s.setAttribute('data-timestamp', +new Date());
  (d.head || d.body).appendChild(s);

  var d = document, s = d.createElement('script');
  s.src = '//npmcharts.disqus.com/count.js';
  s.setAttribute('data-timestamp', +new Date());
  s.setAttribute('id', 'dsq-count-scr');
  (d.head || d.body).appendChild(s);
};

const resetDisqus = (packages) => {
  if (!packages) { return }
  const sortedPackages = packages.slice().sort();
  if (window.DISQUS && window.DISQUSWIDGETS) {
    window.DISQUS.reset({
      reload: true,
      config: function () {  
        this.page.identifier = sortedPackages.join(',')
        this.page.url = 'http://npmcharts.com/compare/' + sortedPackages.join(',');
      }
    })
    DISQUSWIDGETS.getCount({reset: true});
  } else {
    setTimeout(resetDisqus, 500)
  }
}

export default Vue.extend({
  route: {
    waitForData: true,
    data ({ to, next, redirect }) {
      const packageNames = (
        to.path === '/' || !to.params.packages
          ? _.sample(this.presetPackages)
          : to.params.packages.split(',').map(packageName => window.decodeURIComponent(packageName))
      );

      if (to.path === '/' || !to.params.packages) {
        document.title = "npmcharts - compare and graph npm packages";
        this.isUsingPresetPackages = true;
      } else {
        document.title = "npmcharts - compare and graph npm packages - " + to.params.packages.split(',').join(', ');
      }

      ga('send', 'pageview');

      packageNames
      ? npmData.fetch(packageNames, false)
          .then(() => {
            const moduleData = npmData.modules.map(x => ({
{'fraction_non_alphanumeric': 0.17708333333333334, 'fraction_numerical': 0.0014534883720930232, 'mean_word_length': 2.993230174081238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1408022', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1322, 'n_words': 263}