<commit_before>'use strict';

document.addEventListener('DOMContentLoaded', function() {

  /* ==========================================================================
     Creates a new Senna app
     ========================================================================== */

  var app = new senna.App();
  app.setBasePath('/examples/blog');
  app.addSurfaces('posts');
  app.addRoutes(new senna.Route(/\w+\.html/, senna.HtmlScreen));
  app.dispatch();

  /* ==========================================================================
     Creates loading feedback HTML element
     ========================================================================== */

  var loadingFeedback = document.createElement('div');

  loadingFeedback.innerHTML = 'Loading more posts...';
  loadingFeedback.classList.add('loading');

  /* ==========================================================================
     Locks scroll position during navigation
     ========================================================================== */

  var isLoading = false;
  var scrollSensitivity = 0;

  app.on('startNavigate', function(event) {
    isLoading = true;
    scrollSensitivity = 0;

    if (!event.replaceHistory) {
      app.setUpdateScrollPosition(false);
    }
  });

  app.on('endNavigate', function() {
    isLoading = false;

    app.setUpdateScrollPosition(true);
  });

  /* ==========================================================================
     Infinite scrolling logic
     ========================================================================== */

  document.addEventListener('scroll', function() {
    if (window.pageYOffset < 0) {
      return;
    }

    scrollSensitivity++;

    if (isLoading || scrollSensitivity < 5) {
      return;
    }

    if (window.innerHeight * 0.4 > getScrollDistanceToBottom()) {
      debouncedNextPageLoader();
    }
  });

  var debouncedNextPageLoader = senna.debounce(loadNextPage, 100);

  function loadNextPage() {
    if (!app.pendingNavigate && window.nextPage) {
      document.querySelector('#posts').appendChild(loadingFeedback);

      // Goes to the next page using senna.App
      app.navigate(window.nextPage);
    }
  }

  function getScrollDistanceToBottom() {
    return document.body.offsetHeight - window.pageYOffset - window.innerHeight;
  }

});<commit_msg>Removes dependency to external debounce<commit_after>'use strict';

document.addEventListener('DOMContentLoaded', function() {

  /* ==========================================================================
     Creates a new Senna app
     ========================================================================== */

  var app = new senna.App();
  app.setBasePath('/examples/blog');
  app.addSurfaces('posts');
  app.addRoutes(new senna.Route(/\w+\.html/, senna.HtmlScreen));

  /* ==========================================================================
     Creates loading feedback HTML element
     ========================================================================== */

  var loadingFeedback = document.createElement('div');

  loadingFeedback.innerHTML = 'Loading more posts...';
  loadingFeedback.classList.add('loading');

  /* ==========================================================================
     Locks scroll position during navigation
     ========================================================================== */

  var isLoading = false;
  var scrollSensitivity = 0;

  app.on('startNavigate', function(event) {
    isLoading = true;
    scrollSensitivity = 0;

    if (!event.replaceHistory) {
      app.setUpdateScrollPosition(false);
    }
  });

  app.on('endNavigate', function() {
    isLoading = false;

    app.setUpdateScrollPosition(true);
  });

  /* ==========================================================================
     Infinite scrolling logic
     ========================================================================== */

  document.addEventListener('scroll', function() {
    if (window.pageYOffset < 0) {
      return;
    }

    scrollSensitivity++;

    if (isLoading || scrollSensitivity < 5) {
      return;
    }

    if (window.innerHeight * 0.4 > getScrollDistanceToBottom()) {
      debouncedNextPageLoader();
    }
  });

  var debouncedNextPageLoader = debounce(loadNextPage, 100);

  function loadNextPage() {
    if (!app.pendingNavigate && window.nextPage) {
      document.querySelector('#posts').appendChild(loadingFeedback);

      // Goes to the next page using senna.App
      app.navigate(window.nextPage);
    }
  }

  function getScrollDistanceToBottom() {
    return document.body.offsetHeight - window.pageYOffset - window.innerHeight;
  }

  function debounce(fn, delay) {
    return function debounced() {
      var args = arguments;
      debounced.id = setTimeout(function() {
        fn.apply(null, args);
      }, delay);
    };
  }

});
{'fraction_non_alphanumeric': 0.3414734249948697, 'fraction_numerical': 0.003693823106915658, 'mean_word_length': 4.292073832790445, 'pattern_counts': {'":': 0, '<': 7, '<?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': '319957', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1115, 'n_words': 219}