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


(function (define) {
	define(function (require) {
"use strict";

	var domEvents, fireSimpleEvent, watchNode;
		domEvents = require('./events');
	fireSimpleEvent = domEvents.fireSimpleEvent;
	watchNode = domEvents.watchNode;

	/**
	 * Creates a cola adapter for interacting with dom nodes.  Be sure to
	 * unwatch any watches to prevent memory leaks in Internet Explorer 6-8.
	 * @constructor
	 * @param rootNode {Node}
	 * @param options {Object}
	 */
	function NodeAdapter (rootNode, options) {

		this._rootNode = rootNode;

		// set options
		this._options = options;

		// keep data values
		this._values = {};

	}

	NodeAdapter.prototype = {

		getOptions: function () {
			return this._options;
		},

		/**
		 * Watches a specific property and calls back when it changes.
		 * @param name {String} the name of the property to watch.
		 * @param callback {Function} function (propValue, propName) {}
		 * @returns {Function} a function to call when done watching.
		 */
		watch: function (name, callback) {
			var b, node, events, prop, currValues;
			b = this._getBindingsFor(name);
			node = this._getNode(b.node);
			if (b && node) {
				events = 'events' in b ? b.events : guessEventsFor(node);
				prop = 'prop' in b ? b.prop : guessPropFor(node);
				currValues = this._values;
				return listenToNode(node, events, function() {
					var prev, curr;
					// ensure value has changed
					prev = currValues[name];
					curr = getNodePropOrAttr(node, prop);
					if (curr != prev) {
						currValues[name] = curr;
						callback(name, curr);
					}
				});
			}
			else {
				return noop;
			}
		},

		/**
		 * Watches all nodes that have explicit bindings.
		 * Due to lack of bubbling support for many events, we can't
		 * just listen at the root node. Instead, we have to just
		 * listen to all the nodes that are explicitly bound.
		 * @param callback {Function} function (propValue, propName) {}
		 * @returns {Function} a function to call when done watching.
		 */
		watchAll: function (callback) {
			var unwatchers;
			unwatchers = [];
			for (var p in this._options.bindings) {
				unwatchers.push(this.watch(p, callback));
			}
			return function () {
				var unwatcher;
				while ((unwatcher = unwatchers.pop())) unwatcher();
			}
		},

		/**
		 * Signals that a property in a synchronized object has changed.
		 * @param name {String} the name of the changed property
		 * @param value the value of the changed property
		 */
		set: function (name, value) {
			var b, node, prop, current;
			b = this._getBindingsFor(name);
			node = this._getNode(b.node);
			if (b && node) {
				prop = 'prop' in b ? b.prop : guessPropFor(node);
				current = getNodePropOrAttr(node, prop);
				this._values[name] = current;
				if (current != value) {
					setNodePropOrAttr(node, prop, value);
					// notify watchers
					return fireSimpleEvent(node, colaSyntheticEvent);
				}
			}
		},

		forEach: function (lambda) {
			var p, b, node;
			for (p in this._options.bindings) {
				b = this._options.bindings[p];
				node = this._getNode(b.node);
				lambda(getNodePropOrAttr(node, b.prop), p);
			}
		},

		/**
		 * Returns the binding info for a node, if it exists.
		 * @param name {String} the name of the node
		 * @returns {Object} {
		 *     node: aNode,
		 *     prop: 'aProp',
		 *     events: 'event1,event2' // optional
		 * }
		 */
		_getBindingsFor: function (name) {
			var bindings, binding;
			bindings = this._options.bindings;
			if (bindings && name in bindings) {
				binding = bindings[name];
			}
			else {
				binding = {};
			}
			return binding;
		},

		_getNode: function (selector) {
			// TODO: cache querySelector lookups?
			var node;
			if (selector) {
				node = this._options.querySelector(selector, this._rootNode);
				if(!node) {
					node = guessNode(this._rootNode, selector);
				}
			}
			else {
				node = this._rootNode;
			}
			return node;
		}
<commit_msg>no longer fails if bindings are missing<commit_after>/** MIT License (c) copyright <NAME> & <NAME> */


(function (define) {
define(function (require) {
"use strict";

	var domEvents, fireSimpleEvent, watchNode;
		domEvents = require('./events');
	fireSimpleEvent = domEvents.fireSimpleEvent;
	watchNode = domEvents.watchNode;

	/**
	 * Creates a cola adapter for interacting with dom nodes.  Be sure to
	 * unwatch any watches to prevent memory leaks in Internet Explorer 6-8.
	 * @constructor
	 * @param rootNode {Node}
	 * @param options {Object}
	 */
	function NodeAdapter (rootNode, options) {

		this._rootNode = rootNode;

		// set options
		this._options = options;

		// keep data values
		this._values = {};

	}

	NodeAdapter.prototype = {

		getOptions: function () {
			return this._options;
		},

		/**
		 * Watches a specific property and calls back when it changes.
		 * @param name {String} the name of the property to watch.
		 * @param callback {Function} function (propValue, propName) {}
		 * @returns {Function} a function to call when done watching.
		 */
		watch: function (name, callback) {
			var b, node, events, prop, currValues;
			b = this._getBindingsFor(name);
			node = b && this._getNode(b.node);
			if (b && node) {
				events = 'events' in b ? b.events : guessEventsFor(node);
				prop = 'prop' in b ? b.prop : guessPropFor(node);
				currValues = this._values;
				return listenToNode(node, events, function() {
					var prev, curr;
					// ensure value has changed
					prev = currValues[name];
					curr = getNodePropOrAttr(node, prop);
					if (curr != prev) {
						currValues[name] = curr;
						callback(name, curr);
					}
				});
			}
			else {
				return noop;
			}
		},

		/**
		 * Watches all nodes that have explicit bindings.
		 * Due to lack of bubbling support for many events, we can't
		 * just listen at the root node. Instead, we have to just
		 * listen to all the nodes that are explicitly bound.
		 * @param callback {Function} function (propValue, propName) {}
		 * @returns {Function} a function to call when done watching.
		 */
		watchAll: function (callback) {
			var unwatchers;
			unwatchers = [];
			for (var p in this._options.bindings) {
				unwatchers.push(this.watch(p, callback));
			}
			return function () {
				var unwatcher;
				while ((unwatcher = unwatchers.pop())) unwatcher();
			}
		},

		/**
		 * Signals that a property in a synchronized object has changed.
		 * @param name {String} the name of the changed property
		 * @param value the value of the changed property
		 */
		set: function (name, value) {
			var b, node, prop, current;
			b = this._getBindingsFor(name);
			node = b && this._getNode(b.node);
			if (b && node) {
				prop = 'prop' in b ? b.prop : guessPropFor(node);
				current = getNodePropOrAttr(node, prop);
				this._values[name] = current;
				if (current != value) {
					setNodePropOrAttr(node, prop, value);
					// notify watchers
					return fireSimpleEvent(node, colaSyntheticEvent);
				}
			}
		},

		forEach: function (lambda) {
			var p, b, node;
			for (p in this._options.bindings) {
				b = this._options.bindings[p];
				node = this._getNode(b.node);
				lambda(getNodePropOrAttr(node, b.prop), p);
			}
		},

		/**
		 * Returns the binding info for a node, if it exists.
		 * @param name {String} the name of the node
		 * @returns {Object} {
		 *     node: aNode,
		 *     prop: 'aProp',
		 *     events: 'event1,event2' // optional
		 * }
		 */
		_getBindingsFor: function (name) {
			var bindings, binding;
			bindings = this._options.bindings;
			if (bindings && name in bindings) {
				binding = bindings[name];
			}
			return binding;
		},

		_getNode: function (selector) {
			// TODO: cache querySelector lookups?
			var node;
			if (selector) {
				node = this._options.querySelector(selector, this._rootNode);
				if(!node) {
					node = guessNode(this._rootNode, selector);
				}
			}
			else {
				node = this._rootNode;
			}
			return node;
		}

{'fraction_non_alphanumeric': 0.12368024132730016, 'fraction_numerical': 0.001005530417295123, 'mean_word_length': 2.851403678606002, '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': '762884', 'n_tokens_mistral': 3022, 'n_tokens_neox': 2461, 'n_words': 786}