<commit_before>var ZBase = (function() {
  var current_path;
  var current_route;
  var current_view;
  var modules_status = {};
  var modules_waitlist = [];
  var views = {};
  var config;

  var init = function(_config) {
    config = _config;
    changeNavigation(window.location.pathname + window.location.search);
    registerPopstateHandler();

    ZBase.util.header_widget.render();
  };

  var getConfig = function() {
    return config;
  };

  var updateConfig = function(new_config) {
    config = new_config;

    ZBase.util.header_widget.render();
  };

  var showFatalError = function() {
    alert("Fatal Error, please reload the page");
  };

  var showLoader = function() {
    document.getElementById("zbase_main_loader").classList.remove("hidden");
  };

  var hideLoader = function() {
    document.getElementById("zbase_main_loader").classList.add("hidden");
  };

  var registerView = function(view) {
    views[view.name] = view;
  };

  var findRoute = function(path) {
    for (var i = 0; i < config.routes.length; i++) {
      if (path.indexOf(config.routes[i].path_prefix) == 0) {
        return config.routes[i];
      }
    }

    return null;
  };

  /**
   * Navigation
   */
  var registerPopstateHandler = function() {
    window.onpopstate = function(e) {
      e.preventDefault();
      if (e.state && e.state.path) {
        changeNavigation(e.state.path);
      } else {
        changeNavigation(window.location.pathname + window.location.search);
      }
    };
  };

  var applyNavigationChange = function() {
    if (current_view && current_view.name == current_route.view) {
      current_view.handleNavigationChange(current_path);
      hideLoader();
      return;
    }

    if (current_view) {
      current_view.unloadView();
    }

    current_view = views[current_route.view];
    if (!current_view) {
      showFatalError();
      return;
    }

    current_view.loadView({path: current_path, config: config});
    hideLoader();
  };

  var changeNavigation = function(path) {
    console.log(">> Navigate to: ", path);
    showLoader();

    var route = findRoute(path);
    if (route == null) {
      navigateTo(config.default_route);
      return;
    }

    current_route = route;
    current_path = path;

    loadModules(route.modules, function() {
      applyNavigationChange();
    });
  };

  var navigateTo = function(path) {
    history.pushState({path: path}, "", path);
    changeNavigation(path);
  };

  /**
   * Module loading
   */
  var finishModuleDownload = function(module) {
    modules_status[module] = "loaded";
    // fire all finished callbacks
    for (var j = modules_waitlist.length - 1; j >= 0; j--) {
      var entry = modules_waitlist[j];
      for (var i = 0; i < entry.modules.length; i++) {
        if (modules_status[entry.modules[i]] != "loaded") {<commit_msg>bail out on non-app paths<commit_after>var ZBase = (function() {
  var current_path;
  var current_route;
  var current_view;
  var modules_status = {};
  var modules_waitlist = [];
  var views = {};
  var config;

  var init = function(_config) {
    config = _config;
    changeNavigation(window.location.pathname + window.location.search);
    registerPopstateHandler();

    ZBase.util.header_widget.render();
  };

  var getConfig = function() {
    return config;
  };

  var updateConfig = function(new_config) {
    config = new_config;

    ZBase.util.header_widget.render();
  };

  var showFatalError = function() {
    alert("Fatal Error, please reload the page");
  };

  var showLoader = function() {
    document.getElementById("zbase_main_loader").classList.remove("hidden");
  };

  var hideLoader = function() {
    document.getElementById("zbase_main_loader").classList.add("hidden");
  };

  var registerView = function(view) {
    views[view.name] = view;
  };

  var findRoute = function(path) {
    for (var i = 0; i < config.routes.length; i++) {
      if (path.indexOf(config.routes[i].path_prefix) == 0) {
        return config.routes[i];
      }
    }

    return null;
  };

  /**
   * Navigation
   */
  var registerPopstateHandler = function() {
    window.onpopstate = function(e) {
      e.preventDefault();
      if (e.state && e.state.path) {
        changeNavigation(e.state.path);
      } else {
        changeNavigation(window.location.pathname + window.location.search);
      }
    };
  };

  var applyNavigationChange = function() {
    if (current_view && current_view.name == current_route.view) {
      current_view.handleNavigationChange(current_path);
      hideLoader();
      return;
    }

    if (current_view) {
      current_view.unloadView();
    }

    current_view = views[current_route.view];
    if (!current_view) {
      showFatalError();
      return;
    }

    current_view.loadView({path: current_path, config: config});
    hideLoader();
  };

  var changeNavigation = function(path) {
    console.log(">> Navigate to: ", path);
    showLoader();

    var route = findRoute(path);
    if (route == null) {
      if (path.indexOf("/a/") == 0) {
        navigateTo(config.default_route);
      } else {
        window.location.href = path;
      }
      return;
    }

    current_route = route;
    current_path = path;

    loadModules(route.modules, function() {
      applyNavigationChange();
    });
  };

  var navigateTo = function(path) {
    history.pushState({path: path}, "", path);
    changeNavigation(path);
  };

  /**
   * Module loading
   */
  var finishModuleDownload = function(module) {
    modules_status[module] = "loaded";
    // fire all finished callbacks
    for (var j = modules_waitlist.length - 1; j >= 0; j--) {
      var entry = modules_waitlist[j];
      for (var i = 0; i < entry.modules.length; i++) {
        if (modules_status[entry.modules[i]] != "loaded") {
{'fraction_non_alphanumeric': 0.14029644950017237, 'fraction_numerical': 0.0018958979662185454, 'mean_word_length': 2.855813953488372, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '477416', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1788, 'n_words': 362}