<commit_before>export class Router {
  constructor() {

    this._newContent = null;
    this._newContentPromise = Promise.resolve();
    this._viewElement = document.querySelector('section.view-content');
    this._mastHead = this._viewElement.querySelector('div.masthead');
    this._viewContent = this._viewElement.querySelector('div[view]');
    this._isAnimatingOut = false;
    this._isAnimatingIn = false;
    this._spinnerTimeout = 0;
    this._currentPath = window.location.pathname;

    this._boostrapNavigation();
    this._onChanged();
  }

  _queueSpinner() {
    this._spinnerTimeout = setTimeout(() => {
      document.body.classList.add('view-pending');
    }, 500);
  }

  _hideSpinner() {
    document.body.classList.remove('view-pending');
    clearTimeout(this._spinnerTimeout);
  }

  _onChanged() {
    console.log(`Router::_onChanged(${window.location.pathname})`);

    if (this._currentPath === window.location.pathname) {
      console.log('Bumping request');
      return this._loadAsyncScripts();
      return Promise.resolve();
    }

    this._currentPath = window.location.pathname;

    this._newContentPromise = this._loadAsyncView();

    if (this._isAnimatingOut) {
      console.log(' Either animating out or loading still - sorry');
      return Promise.resolve();
    }

    this._isAnimatingOut = true;
    return this._animateOut().then(() => {
      console.log('Router::_animateOut complete');
      this._isAnimatingOut = false;
      return this._newContentPromise;
    }).then(() => {
      console.log(`Async View Resolved With ${this._newContent.getAttribute('id')}`);
      window.scrollTo(0, 0);
      this._swapContents();
      this._animatingIn = true;
      return this._animateIn();
    }).then(() => {
      console.log('Router::_animateIn complete');
      this._animatingIn = false;
      return this._loadAsyncScripts();
    }).catch(error => {
      console.warn(error);
    });
  }

  _swapContents() {
    // Find new mastHead, new mastHead title div, and new view div
    const newMastHead = this._newContent.querySelector('div.masthead');
    const newMastHeadTitle = newMastHead.querySelector('div.masthead-title');
    const newViewContent = this._newContent.querySelector('div[view]');

    // Strip and swap mastHead styles, mastHead title div, and view div content
    this._mastHead.style.cssText = newMastHead.style.cssText;
    this._mastHead.querySelector('div.masthead-title').innerHTML = newMastHeadTitle.innerHTML;
    this._viewContent.innerHTML = newViewContent.innerHTML;

    // Swap IDs over
    this._viewContent.id = newViewContent.id;
  }

  _loadAsyncView() {
    console.log(`Router::_loadAsyncView(${this._currentPath})`);

    return new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();

      xhr.onload = evt => {
        this._newContent = evt.target.response.querySelector('*');
        resolve();
      };

      xhr.onerror = reject;

      xhr.responseType = 'document';
      console.log(`XHR open ${this._currentPath}?partial`)
      xhr.open('GET', `${this._currentPath}?partial`);
      xhr.send();
    });
  }

  _loadAsyncScripts() {
    console.log('Router::loadAsyncScripts');
    return new Promise((resolve, reject) => {
      if (window.location.pathname == '/') {
        require.ensure(['./registration'], function(require) {
          console.log('About to init registration');
          require('./registration').init();
          resolve();
        });
      }
    });
  }

  _animateIn() {
    console.log('Router::_animateIn()');
    this._hideSpinner();

    return new Promise((resolve, reject) => {
      const onTransitionEnd = () => {
        this._viewElement.removeEventListener('transitionend', onTransitionEnd);
        resolve();
      };

      this._viewElement.classList.add('visible');
      this._viewElement.addEventListener('transitionend', onTransitionEnd);
    });
  }

  _animateOut() {<commit_msg>Fix registration module name<commit_after>export class Router {
  constructor() {

    this._newContent = null;
    this._newContentPromise = Promise.resolve();
    this._viewElement = document.querySelector('section.view-content');
    this._mastHead = this._viewElement.querySelector('div.masthead');
    this._viewContent = this._viewElement.querySelector('div[view]');
    this._isAnimatingOut = false;
    this._isAnimatingIn = false;
    this._spinnerTimeout = 0;
    this._currentPath = window.location.pathname;

    this._boostrapNavigation();
    this._onChanged();
  }

  _queueSpinner() {
    this._spinnerTimeout = setTimeout(() => {
      document.body.classList.add('view-pending');
    }, 500);
  }

  _hideSpinner() {
    document.body.classList.remove('view-pending');
    clearTimeout(this._spinnerTimeout);
  }

  _onChanged() {
    console.log(`Router::_onChanged(${window.location.pathname})`);

    if (this._currentPath === window.location.pathname) {
      console.log('Bumping request');
      return this._loadAsyncScripts();
      return Promise.resolve();
    }

    this._currentPath = window.location.pathname;

    this._newContentPromise = this._loadAsyncView();

    if (this._isAnimatingOut) {
      console.log(' Either animating out or loading still - sorry');
      return Promise.resolve();
    }

    this._isAnimatingOut = true;
    return this._animateOut().then(() => {
      console.log('Router::_animateOut complete');
      this._isAnimatingOut = false;
      return this._newContentPromise;
    }).then(() => {
      console.log(`Async View Resolved With ${this._newContent.getAttribute('id')}`);
      window.scrollTo(0, 0);
      this._swapContents();
      this._animatingIn = true;
      return this._animateIn();
    }).then(() => {
      console.log('Router::_animateIn complete');
      this._animatingIn = false;
      return this._loadAsyncScripts();
    }).catch(error => {
      console.warn(error);
    });
  }

  _swapContents() {
    // Find new mastHead, new mastHead title div, and new view div
    const newMastHead = this._newContent.querySelector('div.masthead');
    const newMastHeadTitle = newMastHead.querySelector('div.masthead-title');
    const newViewContent = this._newContent.querySelector('div[view]');

    // Strip and swap mastHead styles, mastHead title div, and view div content
    this._mastHead.style.cssText = newMastHead.style.cssText;
    this._mastHead.querySelector('div.masthead-title').innerHTML = newMastHeadTitle.innerHTML;
    this._viewContent.innerHTML = newViewContent.innerHTML;

    // Swap IDs over
    this._viewContent.id = newViewContent.id;
  }

  _loadAsyncView() {
    console.log(`Router::_loadAsyncView(${this._currentPath})`);

    return new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();

      xhr.onload = evt => {
        this._newContent = evt.target.response.querySelector('*');
        resolve();
      };

      xhr.onerror = reject;

      xhr.responseType = 'document';
      console.log(`XHR open ${this._currentPath}?partial`)
      xhr.open('GET', `${this._currentPath}?partial`);
      xhr.send();
    });
  }

  _loadAsyncScripts() {
    console.log('Router::loadAsyncScripts');
    return new Promise((resolve, reject) => {
      if (window.location.pathname == '/') {
        require.ensure(['./Registration'], function(require) {
          console.log('About to init registration');
          require('./Registration').init();
          resolve();
        });
      }
    });
  }

  _animateIn() {
    console.log('Router::_animateIn()');
    this._hideSpinner();

    return new Promise((resolve, reject) => {
      const onTransitionEnd = () => {
        this._viewElement.removeEventListener('transitionend', onTransitionEnd);
        resolve();
      };

      this._viewElement.classList.add('visible');
      this._viewElement.addEventListener('transitionend', onTransitionEnd);
    });
  }

  _animateOut() {
{'fraction_non_alphanumeric': 0.14619366241636156, 'fraction_numerical': 0.0015149602322939023, 'mean_word_length': 3.2273212379935967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '2857621', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2301, 'n_words': 387}