<commit_before>
  basis.require('basis.ua');
  basis.require('basis.dom.event');


 /**
  * @namespace basis.router
  */

  var namespace = this.path;


  var location = global.location;
  var document = global.document;
  var docMode = document.documentMode;
  var buggyIE = basis.ua.is('IE') && (!docMode || docMode <= 7);
  var eventSupport = 'onhashchange' in global && !buggyIE;

  var CHECK_INTERVAL = 50;
  var NAMED_PARAM = /:\w+/g;
  var SPLAT_PARAM = /\\\*\w+/g;


  function pathToRegExp(route){
    return new RegExp(
      '^' +
      String(route)
        .forRegExp()
        .replace(NAMED_PARAM, '([^\/]+)')
        .replace(SPLAT_PARAM, '(.*?)') +
      '$',
    'i');
  }

  var routes = {};
  var started = false;
  var currentPath;
  var timer;


 /**
  * Start router
  */
  function start(){
    if (!started)
    {
      if (eventSupport)
        basis.dom.event.addHandler(global, 'hashchange', checkUrl);
      else
        timer = setInterval(checkUrl, 50);

      ;;;basis.dev.log(namespace + ' started');
      started = true;

      checkUrl();      
    }
  }

 /**
  * Stop router
  */
  function stop(){
    if (eventSupport)
      basis.dom.event.removeHandler(global, 'hashchange', checkUrl);
    else
      clearInterval(timer);

    ;;;basis.dev.log(namespace + ' stopped');
    started = false;
  }

 /**
  * Process current location
  */
  function checkUrl(){
    var newPath = location.hash.substr(1) || '/';

    if (newPath != currentPath)
    {
      ;;;basis.dev.log(namespace + ' hash changed:', newPath);
      currentPath = newPath;

      for (var path in routes)
      {
        var route = routes[path];
        var match = newPath.match(route.regexp);
        if (match)
        {
          var args = basis.array.from(match, 1);
          var callbacks = basis.array.from(route.callbacks);
          for (var i = 0, item; item = callbacks[i]; i++)
            item.callback.apply(item.context, args);

          ;;;basis.dev.log(namespace + ' hash match:', route.source, args);
        }
      }
    }
  }

 /**
  * Add path to be handled
  */
  function add(path, callback, context){
    var route = routes[path];

    if (!route)
    {
      route = {
        source: path,
        callbacks: [],
        regexp: Object.prototype.toString.call(path) != '[object RegExp]'
          ? pathToRegExp(path)
          : path
      };
      routes[path] = route;
    }
    
    route.callbacks.push({
      callback: callback,
      context: context
    });

    if (currentPath)
    {
      var match = currentPath.match(route.regexp);
      if (match)
        callback.apply(context, basis.array.from(match, 1));
    }
  }

 /**
  * Navigate to specified path
  */
  function navigate(path, replace){
    if (replace)
      location.replace(location.pathname + '#' + path);
    else
      location.hash = path;

    if (started)
      checkUrl();
  }

  //
  // export names
  //

  module.exports = {
    add: add,
    stop: stop,
    start: start,
    checkUrl: checkUrl,
    navigate: navigate
  };<commit_msg>remove callback function implemented, small code refactoring<commit_after>
  basis.require('basis.ua');
  basis.require('basis.dom.event');


 /**
  * @namespace basis.router
  */

  var namespace = this.path;


  //
  // main part
  //

  var location = global.location;
  var document = global.document;
  var docMode = document.documentMode;
  var buggyIE = basis.ua.is('IE') && (!docMode || docMode <= 7);
  var eventSupport = 'onhashchange' in global && !buggyIE;

  var CHECK_INTERVAL = 50;
  var NAMED_PARAM = /:\w+/g;
  var SPLAT_PARAM = /\\\*\w+/g;

  var routes = {};
  var started = false;
  var currentPath;
  var timer;
  var match;


  function pathToRegExp(route){
    return new RegExp(
      '^' +
      String(route)
        .forRegExp()
        .replace(NAMED_PARAM, '([^\/]+)')
        .replace(SPLAT_PARAM, '(.*?)')
      + '$',
    'i');
  }

  function startWatch(){
    if (eventSupport)
      basis.dom.event.addHandler(global, 'hashchange', checkUrl);
    else
      timer = setInterval(checkUrl, CHECK_INTERVAL);
  }
  function stopWatch(){
    if (eventSupport)
      basis.dom.event.removeHandler(global, 'hashchange', checkUrl);
    else
      clearInterval(timer);
  }


 /**
  * Start router
  */
  function start(){
    if (!started)
    {
      startWatch();

      ;;;basis.dev.log(namespace + ' started');
      started = true;

      checkUrl();      
    }
  }

 /**
  * Stop router
  */
  function stop(){
    if (started)
    {
      stopWatch();

      ;;;basis.dev.log(namespace + ' stopped');
      started = false;
    }
  }

 /**
  * Process current location
  */
  function checkUrl(){
    var newPath = location.hash.substr(1) || '/';

    if (newPath != currentPath)
    {
      ;;;basis.dev.log(namespace + ' hash changed:', newPath);
      currentPath = newPath;

      for (var path in routes)
      {
        var route = routes[path];
        var match = newPath.match(route.regexp);
        if (match)
        {
          var args = basis.array.from(match, 1);
          var callbacks = basis.array.from(route.callbacks);
          for (var i = 0, item; item = callbacks[i]; i++)
            item.callback.apply(item.context, args);

          ;;;basis.dev.log(namespace + ' hash match:', route.source, args);
        }
      }
    }
  }

 /**
  * Add path to be handled
  */
  function add(path, callback, context){
    var route = routes[path];

    if (!route)
    {
      route = {
        source: path,
        callbacks: [],
        regexp: Object.prototype.toString.call(path) != '[object RegExp]'
          ? pathToRegExp(path)
          : path
      };
      routes[path] = route;
    }
    
    route.callbacks.push({
      callback: callback,
      context: context
    });

    if (currentPath)
    {
      var match = currentPath.match(route.regexp);
      if (match)
        callback.apply(context, basis.array.from(match, 1));
    }
  }

 /**
  * Remove handler for path
  */ 
  function remove(path, callback, context){
    var route = routes[path];

    if (route)
      for (var i = 0, cb; cb = route.callbacks[i]; i++)
        if (cb.callback === callback && cb.context === context)
        {
          route.callbacks.splice(i, 1);
          return;
        }
  }

 /**
  * Navigate to specified path
  */
  function navigate(path, replace){
    if (replace)
      location.replace(location.pathname + '#' + path);
    else
      location.hash = path;

    if (started)
      checkUrl();
  }

  //
  // export names
  //

  module.exports = {
    add: add,
    remove: remove,
    stop: stop,
    start: start,
    checkUrl: checkUrl,
    navigate: navigate
  };
{'fraction_non_alphanumeric': 0.15034338608539863, 'fraction_numerical': 0.0026873693639892504, 'mean_word_length': 2.0899446494464944, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6136910', 'n_tokens_mistral': 2232, 'n_tokens_neox': 2137, 'n_words': 479}