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

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

	var undef;

	/**
	 * Decorator that makes an object watchable. Similar to dojo's Stateful.
	 * The original object is unaltered, but an object that inherits from the
	 * original object with the watchable methods (get, set, and watch) is
	 * returned.
	 * @param obj {Object} an object to be made watchable.
	 * @returns {WatchableObject}
	 */
	function makeWatchable (obj) {

		var watchable, listeners;

		// just return the object if it's already watchable
		if (makeWatchable.isWatchable(obj)) return obj;

		watchable = begetWatchable(obj);

		listeners = {};

		/**
		 * Returns a property or attribute of an object.
		 * @param name {String}
		 * @param options {Object}
		 * @returns the value of the property or attribute
		 */
		watchable.get = function (name, options) {
			return obj[name];
		};

		/**
		 * Sets a property or attribute of a obj.
		 * @param name {String}
		 * @param value
		 * @param options {Object}
		 * @returns {Object}
		 */
		watchable.set = function (name, value, options) {
			obj[name] = value;
			notify(value, name);
			notify(value, '*', name); // also notify any wildcard listeners
			return obj;
		};

		/**
		 * Watches for data set on the property specified by name
		 * and returns an unwatch function. Note: only property modifications
		 * made through this interface are watchable with this adapter!
		 * @param name {String}
		 * @param callback {Function} function (propValue, propName) {}
		 * @returns {Function} function () {} (no params)
		 */
		watchable.watch = function (name, callback) {
			return listen(name, callback);
		};

		return watchable;

		/**
		 * Registers a listener and returns a function to unlisten.
		 * Internal implementation of watch/unwatch.
		 * @private
		 * @param name {String}
		 * @param callback {Function}
		 */
		function listen (name, callback) {
			var list, head;

			list = listeners[name];
			head = { callback: callback, prev: list };
			listeners[name] = head;

			// return unwatch function
			return function () {
				walkList(listeners[name], function (item) {
					if (item == head) {
						listeners[name] = head.prev;
						return walkList.stopSignal;
					}
				});
			};
		}

		/**
		 * Calls all listener functions with the details of a modified
		 * property.
		 * @private
		 * @param value
		 * @param key
		 */
		function notify (value, key, name) {
			if (arguments.length < 3) name = key;
			walkList(listeners[key], function (item) {
				item.callback(value, name);
			});
		}

	}

	makeWatchable.isWatchable = isWatchable;

		function WatchableObject () {}
	function begetWatchable (obj){
		var watchable;
		WatchableObject.prototype = obj;
		watchable = new WatchableObject();
		WatchableObject.prototype = begetWatchable.cleanPrototype;
		return watchable;
	}
	begetWatchable.cleanPrototype = {};

	/**
	 * Walks a linked list
	 * @private
	 * @param list
	 * @param callback {Function} function (itemInList, callback) {}
	 */
	function walkList (list, callback) {
		var item = list;<commit_msg>Watchable only notifies listeners when the property actually changes, not when it's just set (to potentially the same value). also: some cleanup of unused features<commit_after>/** MIT License (c) copyright <NAME> & <NAME> */

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

	var undef;

	/**
	 * Decorator that makes an object watchable. Similar to dojo's Stateful.
	 * The original object is unaltered, but an object that inherits from the
	 * original object with the watchable methods (get, set, and watch) is
	 * returned.
	 * @param obj {Object} an object to be made watchable.
	 * @returns {WatchableObject}
	 */
	function makeWatchable (obj) {

		var watchable, listeners;

		// just return the object if it's already watchable
		if (makeWatchable.isWatchable(obj)) return obj;

		watchable = begetWatchable(obj);

		listeners = {};

		/**
		 * Returns a property or attribute of an object.
		 * @param name {String}
		 * @returns the value of the property or attribute
		 */
		watchable.get = function (name) {
			return obj[name];
		};

		/**
		 * Sets a property or attribute of a obj.
		 * @param name {String}
		 * @param value
		 */
		watchable.set = function (name, value) {
			if (obj[name] != value) {
				obj[name] = value;
				notify(value, name);
				notify(value, '*', name); // also notify any wildcard listeners
			}
		};

		/**
		 * Watches for data set on the property specified by name
		 * and returns an unwatch function. Note: only property modifications
		 * made through this interface are watchable with this adapter!
		 * @param name {String}
		 * @param callback {Function} function (propValue, propName) {}
		 * @returns {Function} function () {} (no params)
		 */
		watchable.watch = function (name, callback) {
			return listen(name, callback);
		};

		return watchable;

		/**
		 * Registers a listener and returns a function to unlisten.
		 * Internal implementation of watch/unwatch.
		 * @private
		 * @param name {String}
		 * @param callback {Function}
		 */
		function listen (name, callback) {
			var list, head;

			list = listeners[name];
			head = { callback: callback, prev: list };
			listeners[name] = head;

			// return unwatch function
			return function () {
				walkList(listeners[name], function (item) {
					if (item == head) {
						listeners[name] = head.prev;
						return walkList.stopSignal;
					}
				});
			};
		}

		/**
		 * Calls all listener functions with the details of a modified
		 * property.
		 * @private
		 * @param value
		 * @param key
		 */
		function notify (value, key, name) {
			if (arguments.length < 3) name = key;
			walkList(listeners[key], function (item) {
				item.callback(value, name);
			});
		}

	}

	makeWatchable.isWatchable = isWatchable;

	function WatchableObject () {}
	function begetWatchable (obj){
		var watchable;
		WatchableObject.prototype = obj;
		watchable = new WatchableObject();
		WatchableObject.prototype = begetWatchable.cleanPrototype;
		return watchable;
	}
	begetWatchable.cleanPrototype = {};

	/**
	 * Walks a linked list
	 * @private
	 * @param list
	 * @param callback {Function} function (itemInList, callback) {}
	 */
	function walkList (list, callback) {
		var item = list;
{'fraction_non_alphanumeric': 0.11585750315258513, 'fraction_numerical': 0.00031525851197982345, 'mean_word_length': 3.182597231377719, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1140750', 'n_tokens_mistral': 2180, 'n_tokens_neox': 1819, 'n_words': 646}