<commit_before>OC.router_base_url = OC.webroot + '/index.php/',
OC.Router = {
	routes_request: $.ajax(OC.router_base_url + 'core/routes.json', {
		dataType: 'json',
		success: function(jsondata) {
			if (jsondata.status == 'success') {
				OC.Router.routes = jsondata.data;
			}
		}
	}),
	generate:function(name, opt_params) {
		if (!('routes' in this)) {
			if(this.routes_request.state() != 'resolved') {
				alert('wait');// wait
			}
		}
		if (!(name in this.routes)) {
			throw new Error('The route "' + name + '" does not exist.');
		}<commit_msg>Prevent ajax race conditions when using routes by offering a callback that is run after the the routes have finished loading<commit_after>OC.router_base_url = OC.webroot + '/index.php/',
OC.Router = {
	loadedCallback: null,
	// register your ajax requests to load after the loading of the routes
	// has finished. otherwise you face problems with race conditions
	registerLoadedCallback: function(callback){
		if(this.routes_request.state() === 'resolved'){
			callback();
		} else {
			this.loadedCallback = callback;
		}
	},
	routes_request: $.ajax(OC.router_base_url + 'core/routes.json', {
		dataType: 'json',
		success: function(jsondata) {
			if (jsondata.status === 'success') {
				OC.Router.routes = jsondata.data;
				if(OC.Router.loadedCallback !== null){
					OC.Router.loadedCallback();
				}
			}
		}
	}),
	generate:function(name, opt_params) {
		if (!('routes' in this)) {
			if(this.routes_request.state() != 'resolved') {
				alert('To avoid race conditions, please register a callback');// wait
			}
		}
		if (!(name in this.routes)) {
			throw new Error('The route "' + name + '" does not exist.');
		}
{'fraction_non_alphanumeric': 0.15770609318996415, 'fraction_numerical': 0.0, 'mean_word_length': 3.67877094972067, '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': '2309518', 'n_tokens_mistral': 602, 'n_tokens_neox': 554, 'n_words': 137}