<commit_before>define(['abyssa-with-deps', 'qajax'], function (abyssa, qajax) {

  return function (targets) {

    qajax.getJSON("/router").then(function (routes) {
      var router = abyssa.Router();
      routes.forEach(function (route) {
        var pattern = route.path.reduce(function (acc, part) {
          if (typeof part === 'string') return acc + part;
          else return acc + ':' + part.name; // TODO handle regexp constraints
        }, '');
        var state = abyssa.State(pattern, function () {
          if (!router.isFirstTransition()) {
            targets[route.call.controller][route.call.method].apply(null, arguments)
          }
        });
        router.addState(route.call.controller + '_' + route.call.method, state);
      });
      router.init();
    });

  }

});<commit_msg>update client-side router generation<commit_after>define(['abyssa-with-deps', 'qajax'], function (abyssa, qajax) {

  return function (targets) {

    qajax.getJSON("/router").then(function (routes) {
      var router = abyssa.Router();
      var processRules = function (rules, prefix) {
        rules.forEach(function (rule) {
          if (rule.type === 'route') {
            var pattern = rule.path.reduce(function (acc, part) {
              if (typeof part === 'string') return acc + part;
              else return acc + ':' + part.name; // TODO handle regexp constraints
            }, prefix);
            var state = abyssa.State(pattern, function () {
              if (!router.isFirstTransition()) {
                targets[rule.call.controller][rule.call.method].apply(null, arguments)
              }
            });
            router.addState(rule.call.controller + '_' + rule.call.method, state);
          } else /* rule.type === 'router' */ {
            processRules(rule.rules, prefix + rule.prefix);
          }
        });
      };

      // I assume that the root object is always a router with prefix '/'
      processRules(routes.rules, '');

      router.init();
    });

  }

});
{'fraction_non_alphanumeric': 0.1531219028741328, 'fraction_numerical': 0.0, 'mean_word_length': 2.1996830427892236, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3286334', 'n_tokens_mistral': 577, 'n_tokens_neox': 565, 'n_words': 125}