<commit_before>/** @license MIT License (c) copyright <NAME> & <NAME> */

/**
 * wire/cola plugin
 *
 * wire is part of the cujo.js family of libraries (http://cujojs.com/)
 *
 * Licensed under the MIT License at:
 * http://www.opensource.org/licenses/mit-license.php
 */

(function(define) {
define(['when', 'cola/AdapterResolver',
	'cola/ArrayAdapter', 'cola/dom/NodeListAdapter',
	'cola/ResultSetAdapter', 'cola/QueryAdapter', 'cola/mediator/syncCollections',
	'cola/ObjectAdapter', 'cola/dom/NodeAdapter',
	'cola/ResultAdapter', 'cola/mediator/syncProperties',
	'cola/transform/enum', 'cola/transform/expression', 'cola/addPropertyTransforms',
	'cola/transformCollection', 'cola/transform/compose'],
function(when, adapterResolver,
	ArrayAdapter, NodeListAdapter, ResultSetAdapter, QueryAdapter, syncCollections,
	ObjectAdapter, NodeAdapter,
	ResultAdapter, syncProperties,
	createEnumTransformer, createExpressionTransformer, addPropertyTransforms,
	transformCollection, compose
) {

	var cachedBindings, isArray;

	// TODO: move most of this stuff, including adapter registration to cola.js
	// TODO: implement wire$build that auto-adds these deps to build
	adapterResolver.register(ArrayAdapter, 'collection');
	adapterResolver.register(NodeListAdapter, 'collection');
//	adapterResolver.register(ResultSetAdapter, 'collection');
	adapterResolver.register(QueryAdapter, 'collection');
	adapterResolver.register(NodeAdapter, 'object');
	adapterResolver.register(ObjectAdapter, 'object');
//	adapterResolver.register(ResultAdapter, 'object');

	function querySelector (selector, node) {
		return node.querySelector(selector);
	}

	isArray = Array.isArray || function(it) {
		return Object.prototype.toString.call(it) == '[object Array]';
	};

	/**
	 * "globally" cached bindings.  Cache bindings here so that a bind can find,
	 * process, and remove them later
	 * @private
 	 */
	cachedBindings = [];

	/**
	 * @private
	 * @param target anything - target component for which to find cached bindings
	 * @param found {Function} function to call with existing cached bindings
	 * @param [notFound] {Function} function to call if no cached bindings found
	 */
	function findCachedBindings(target, found, notFound) {
		for(var i = 0, len = cachedBindings.length; i < len; i++) {
			if(cachedBindings[i].target === target) {
				return found(cachedBindings, i, cachedBindings[i]);
			}
		}

		return notFound(cachedBindings);
	}

	function mixin(dst, src) {
		for(var p in src) {
			dst[p] = src[p];
		}
		return dst;
	}

	function mergeBindings(bindingDef, bindings) {
		mixin(bindingDef.bindings, bindings);
	}

	function createPropertyTransform(transforms, wire) {

		if(!isArray(transforms)) {
			transforms = [transforms];
		}

		return when.reduce(transforms,
			function(txList, txSpec) {
				var name;

				for(name in txSpec) {
					if(name != 'inverse') break;
				}

				return when(wire.resolveRef(name),
					function(createTransform) {
						var transform = createTransform(txSpec[name]);
						txList.push(txSpec.inverse ? transform.inverse : transform);
						return txList;
					}
				);
			}, []).then(
			function(txList) {
				return txList.length > 1 ? compose(txList) : txList[0];
			}
		);
	}

	function setupBinding(bindingSpecs, name, wire) {
		var bindingSpec, binding;

		bindingSpec = mixin({}, bindingSpecs[name]);
		binding = {
			name: name,
			spec: bindingSpec
		};

		return bindingSpec.transform
			? when(createPropertyTransform(bindingSpec.transform, wire),
				function(propertyTransform) {
					binding.spec.transform = propertyTransform;
					return binding;<commit_msg>Property transforms are now actual transform functions rather than factories. They may be parameterized, or not.  Supports , string names, or an object with a key that is the name of a transform function component.  Supports an array of any/all of the above (can be mixed)<commit_after>/** @license MIT License (c) copyright <NAME> & <NAME> */

/**
 * wire/cola plugin
 *
 * wire is part of the cujo.js family of libraries (http://cujojs.com/)
 *
 * Licensed under the MIT License at:
 * http://www.opensource.org/licenses/mit-license.php
 */

(function(define) {
define(['when', 'cola/AdapterResolver',
	'cola/ArrayAdapter', 'cola/dom/NodeListAdapter',
	'cola/ResultSetAdapter', 'cola/QueryAdapter', 'cola/mediator/syncCollections',
	'cola/ObjectAdapter', 'cola/dom/NodeAdapter',
	'cola/ResultAdapter', 'cola/mediator/syncProperties',
	'cola/addPropertyTransforms', 'cola/transformCollection', 'cola/transform/compose'],
function(when, adapterResolver,
	ArrayAdapter, NodeListAdapter, ResultSetAdapter, QueryAdapter, syncCollections,
	ObjectAdapter, NodeAdapter,
	ResultAdapter, syncProperties,
	addPropertyTransforms, transformCollection, compose
) {

	var cachedBindings, isArray, undef, slice;

	// TODO: move most of this stuff, including adapter registration to cola.js
	// TODO: implement wire$build that auto-adds these deps to build
	adapterResolver.register(ArrayAdapter, 'collection');
	adapterResolver.register(NodeListAdapter, 'collection');
//	adapterResolver.register(ResultSetAdapter, 'collection');
	adapterResolver.register(QueryAdapter, 'collection');
	adapterResolver.register(NodeAdapter, 'object');
	adapterResolver.register(ObjectAdapter, 'object');
//	adapterResolver.register(ResultAdapter, 'object');

	function querySelector (selector, node) {
		return node.querySelector(selector);
	}

	isArray = Array.isArray || function(it) {
		return Object.prototype.toString.call(it) == '[object Array]';
	};

	slice = Array.prototype.slice;

	/**
	 * "globally" cached bindings.  Cache bindings here so that a bind can find,
	 * process, and remove them later
	 * @private
 	 */
	cachedBindings = [];

	/**
	 * @private
	 * @param target anything - target component for which to find cached bindings
	 * @param found {Function} function to call with existing cached bindings
	 * @param [notFound] {Function} function to call if no cached bindings found
	 */
	function findCachedBindings(target, found, notFound) {
		for(var i = 0, len = cachedBindings.length; i < len; i++) {
			if(cachedBindings[i].target === target) {
				return found(cachedBindings, i, cachedBindings[i]);
			}
		}

		return notFound(cachedBindings);
	}

	function mixin(dst, src) {
		for(var p in src) {
			dst[p] = src[p];
		}
		return dst;
	}

	function mergeBindings(bindingDef, bindings) {
		mixin(bindingDef.bindings, bindings);
	}

	function createPropertyTransform(transforms, wire) {

		if(typeof transforms == 'function') {
			// If it's a function, just use it
			return transforms;
		} else if(typeof transforms == 'string') {
			// If it's a string, assume it's the name of a component
			// that is a transform function, and resolve it.
			return wire.resolveRef(transforms);
		}

		if(!isArray(transforms)) {
			transforms = [transforms];
		}

		return when.reduce(transforms,
			function(txList, txSpec) {
				var name;

				// Determine the name of the transform and try
				// to resolve it as a component in the current
				// wire spec
				if(typeof txSpec == 'string') {
					name = txSpec;
				} else {
					for(name in txSpec) {
						if(name != 'inverse') break;
					}
				}

				return when(wire.resolveRef(name),
					function(transform) {
						txList.push(function() {
							var args = slice.call(arguments);
							return transform.apply(undef, args.concat(txSpec[name]));
						});
						return txList;
					}
				);
			}, [])
		.then(
			function(txList) {
				return txList.length > 1 ? compose(txList) : txList[0];
			}
		);
	}

	function setupBinding(bindingSpecs, name, wire) {
		var bindingSpec, binding;

		bindingSpec = mixin({}, bindingSpecs[name]);
		binding = {
			name: name,
			spec: bindingSpec
		};

		return bindingSpec.transform
			? when(createPropertyTransform(bindingSpec.transform, wire),
				function(propertyTransform) {
					binding.spec.transform = propertyTransform;
					return binding;
{'fraction_non_alphanumeric': 0.12408759124087591, 'fraction_numerical': 0.0007550969041026932, 'mean_word_length': 4.242084432717678, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6823211', 'n_tokens_mistral': 2654, 'n_tokens_neox': 2350, 'n_words': 622}