<commit_before>﻿; (function() {

	function execute() {
		var log = ExoWeb.trace.log;
		var throwAndLog = ExoWeb.trace.throwAndLog;

		Type.registerNamespace("ExoWeb.View");

		// Markup Extensions
		//////////////////////////////////////////////////////////////////////////////////////

		// Metadata adapter markup extension
		Sys.Application.registerMarkupExtension("@",
			function AdapterMarkupExtention(component, targetProperty, templateContext, properties) {
				log(["@", "markupExt"], "@ " + (properties.$default || "(no path)") + " (evaluating)");

				var path = properties.path || properties.$default;
				delete properties.$default;

				var adapter = new Adapter(properties.source || templateContext.dataItem, path, properties.systemFormat, properties.displayFormat, properties);

				adapter.ready(function AdapterReady() {
					log(["@", "markupExt"], "@ " + (adapter._propertyPath || "(no path)") + "  <.>");
					Sys.Observer.setValue(component, targetProperty, adapter);
				});
			}, false);

		// Lazy eval markup extension
		Sys.Application.registerMarkupExtension("~",
			function LazyMarkupExtension(component, targetProperty, templateContext, properties) {
				log(["~", "markupExt"], "~ " + (properties.$default || "(no path)") + " (evaluating)");

				var source;
				var scopeChain;

				if (properties.source) {
					var evalSource = new Function("$element", "$index", "$dataItem", "return " + properties.source + ";");
					source = evalSource(component.get_element(), templateContext.index, templateContext.dataItem);

					// don't try to eval the path against window
					scopeChain = [];
				}
				else {
					source = templateContext.dataItem;
				}

				ExoWeb.Model.LazyLoader.eval(source, properties.$default,
					function(result) {
						log(["~", "markupExt"], "~ " + (properties.$default || "(no path)") + "  <.>");

						if (properties.transform && result instanceof Array) {
							// generate transform function
							var doTrans = new Function("list", "$element", "$index", "$dataItem", "return $transform(list)." + properties.transform + ";");

							// transform the result to use now
							var list = result;
							result = doTrans(list, component.get_element(), templateContext.index, templateContext.dataItem);

							// watch for changes to the list and refresh
							Sys.Observer.makeObservable(list);
							Sys.Observer.addCollectionChanged(list, function() {
								Sys.Observer.setValue(component, targetProperty, doTrans(list, component.get_element(), templateContext.index, templateContext.dataItem));
							});
						}
						else {
							function doFormat(obj) {
								if (properties.format && result.constructor.formats && result.constructor.formats[properties.format])
									return obj.constructor.formats[properties.format].convert(obj);

								return obj;
							}

							if (properties.$default) {
								var props = properties.$default.split(".");
								var last = props.splice(-1);
								ExoWeb.Model.LazyLoader.eval(source, props.join("."), function(target) {
									Sys.Observer.addSpecificPropertyChanged(target, last, function(obj) {
										Sys.Observer.setValue(component, targetProperty, doFormat(ExoWeb.getValue(target, last)));
									});
								},
								function(err) {
									throwAndLog(["~", "markupExt"], "Couldn't listen for change events on '{0}', {1}", [properties.$default, err]);
								});
							}

							result = doFormat(result);
						}

						try {
							if (properties.required) {
								var path = properties.required;

								// check for instance property format
								if (path.startsWith("this."))
									path = path.substring(5);

								ExoWeb.Model.LazyLoader.eval(source, path, function() {
									Sys.Observer.setValue(component, targetProperty, result);
								});
							}
							else {
								Sys.Observer.setValue(component, targetProperty, result);
							}
						}
						catch (err) {
							throwAndLog(["~", "markupExt"], "Path '{0}' was evaluated but the '{2}' property on the target could not be set, {1}", [properties.$default, err, targetProperty]);
						}
					},<commit_msg>lazy load extension load required path relative to the extension result rather than the original source<commit_after>﻿; (function() {

	function execute() {
		var log = ExoWeb.trace.log;
		var throwAndLog = ExoWeb.trace.throwAndLog;

		Type.registerNamespace("ExoWeb.View");

		// Markup Extensions
		//////////////////////////////////////////////////////////////////////////////////////

		// Metadata adapter markup extension
		Sys.Application.registerMarkupExtension("@",
			function AdapterMarkupExtention(component, targetProperty, templateContext, properties) {
				log(["@", "markupExt"], "@ " + (properties.$default || "(no path)") + " (evaluating)");

				var path = properties.path || properties.$default;
				delete properties.$default;

				var adapter = new Adapter(properties.source || templateContext.dataItem, path, properties.systemFormat, properties.displayFormat, properties);

				adapter.ready(function AdapterReady() {
					log(["@", "markupExt"], "@ " + (adapter._propertyPath || "(no path)") + "  <.>");
					Sys.Observer.setValue(component, targetProperty, adapter);
				});
			}, false);

		// Lazy eval markup extension
		Sys.Application.registerMarkupExtension("~",
			function LazyMarkupExtension(component, targetProperty, templateContext, properties) {
				log(["~", "markupExt"], "~ " + (properties.$default || "(no path)") + " (evaluating)");

				var source;
				var scopeChain;

				if (properties.source) {
					var evalSource = new Function("$element", "$index", "$dataItem", "return " + properties.source + ";");
					source = evalSource(component.get_element(), templateContext.index, templateContext.dataItem);

					// don't try to eval the path against window
					scopeChain = [];
				}
				else {
					source = templateContext.dataItem;
				}

				ExoWeb.Model.LazyLoader.eval(source, properties.$default,
					function(result) {
						log(["~", "markupExt"], "~ " + (properties.$default || "(no path)") + "  <.>");

						var target = result;

						if (properties.transform && result instanceof Array) {
							// generate transform function
							var doTrans = new Function("list", "$element", "$index", "$dataItem", "return $transform(list)." + properties.transform + ";");

							// transform the result to use now
							var list = result;
							result = doTrans(list, component.get_element(), templateContext.index, templateContext.dataItem);

							// watch for changes to the list and refresh
							Sys.Observer.makeObservable(list);
							Sys.Observer.addCollectionChanged(list, function() {
								Sys.Observer.setValue(component, targetProperty, doTrans(list, component.get_element(), templateContext.index, templateContext.dataItem));
							});
						}
						else {
							function doFormat(obj) {
								if (properties.format && result.constructor.formats && result.constructor.formats[properties.format])
									return obj.constructor.formats[properties.format].convert(obj);

								return obj;
							}

							if (properties.$default) {
								var props = properties.$default.split(".");
								var lastProp = props.splice(-1);
								ExoWeb.Model.LazyLoader.eval(source, props.join("."), function(lastTarget) {
									Sys.Observer.addSpecificPropertyChanged(lastTarget, lastProp, function(obj) {
										Sys.Observer.setValue(component, targetProperty, doFormat(ExoWeb.getValue(lastTarget, lastProp)));
									});
								},
								function(err) {
									throwAndLog(["~", "markupExt"], "Couldn't listen for change events on '{0}', {1}", [properties.$default, err]);
								});
							}

							result = doFormat(result);
						}

						try {
							if (properties.required) {
								var path = properties.required;

								// check for instance property format
								if (path.startsWith("this."))
									path = path.substring(5);

								ExoWeb.Model.LazyLoader.eval(target, path, function() {
									Sys.Observer.setValue(component, targetProperty, result);
								});
							}
							else {
								Sys.Observer.setValue(component, targetProperty, result);
							}
						}
						catch (err) {
							throwAndLog(["~", "markupExt"], "Path '{0}' was evaluated but the '{2}' property on the target could not be set, {1}", [properties.$default, err, targetProperty]);
						}
					},
{'fraction_non_alphanumeric': 0.16413301662707838, 'fraction_numerical': 0.00166270783847981, 'mean_word_length': 2.8932038834951457, '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': '1435005', 'n_tokens_mistral': 3126, 'n_tokens_neox': 2270, 'n_words': 518}