<commit_before>xhr = {
	post:function(path, args, responseHandler) {
		return xhr._send('post', path, args, responseHandler)
	},
	get: function(path, args, responseHandler) {
		return xhr._send('get', path, args, responseHandler)
	},
	postJson:function(path, args, responseHandler) {
		return xhr._send('post', path, args, responseHandler, { 'Content-Type':'application/json' })
	},
	_send: function(method, path, args, responseHandler, headers) {
		result = { loading:true, error:null, response:null }
		<script method=method path=path args=args responseHandler=responseHandler headers=headers result=result>
			if (!__hackFirstExecution) { return }
			var xhr = require('fun/node_modules/std/xhr')
			xhr[method.asString()](path.asString(), args && args.asJSONObject(), function(err, response) {
				if (err) {
					err = { text:err.message }
				}
				if (responseHandler && !responseHandler.isNull()) {
					var event = fun.expressions.fromJsValue({ type:'xhr-response', error:err, response:response })
					responseHandler.invoke(null, event)
				}
				result.set(['loading'], fun.expressions.No)
				if (err) {
					result.set(['error'], fun.expressions.fromJsValue(err))
				} else {
					result.set(['response'], fun.expressions.fromJsValue(response))
				}
			}, headers && headers.asJSONObject())
		</script>
		return result
	}
}<commit_msg>Add xhr.loading<commit_after>xhr = {
	post:function(path, args, responseHandler) {
		return xhr._send('post', path, args, responseHandler)
	},
	get: function(path, args, responseHandler) {
		return xhr._send('get', path, args, responseHandler)
	},
	postJson:function(path, args, responseHandler) {
		return xhr._send('post', path, args, responseHandler, { 'Content-Type':'application/json' })
	},
	_send: function(method, path, args, responseHandler, headers) {
		result = { loading:true, error:null, response:null }
		<script method=method path=path args=args responseHandler=responseHandler headers=headers result=result module=xhr>
			if (!__hackFirstExecution) { return }
			
			module.set(['loading'], fun.expressions.Yes)
			module = module.evaluate()
			if (module._loadingCount) { module._loadingCount += 1 }
			else { module._loadingCount = 1 }
			
			var xhr = require('fun/node_modules/std/xhr')
			xhr[method.asString()](path.asString(), args && args.asJSONObject(), function(err, response) {
				if (err) {
					err = { text:err.message }
				}
				if (responseHandler && !responseHandler.isNull()) {
					var event = fun.expressions.fromJsValue({ type:'xhr-response', error:err, response:response })
					responseHandler.invoke(null, event)
				}
				result.set(['loading'], fun.expressions.No)
				if (err) {
					result.set(['error'], fun.expressions.fromJsValue(err))
				} else {
					result.set(['response'], fun.expressions.fromJsValue(response))
				}
				
				if (!--module._loadingCount) {
					module.set(['loading'], fun.expressions.No)
				}
			}, headers && headers.asJSONObject())
		</script>
		return result
	},
	loading: false
}
{'fraction_non_alphanumeric': 0.15619807244931871, 'fraction_numerical': 0.0006646726487205051, 'mean_word_length': 4.375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3906321', 'n_tokens_mistral': 1092, 'n_tokens_neox': 939, 'n_words': 187}