<commit_before>/**
 * Composer.js is an MVC framework for creating and organizing javascript
 * applications. For documentation, please visit:
 *
 *     http://lyonbros.github.com/composer.js/
 *
 * -----------------------------------------------------------------------------
 *
 * Copyright (c) 2011, Lyon Bros Enterprises, LLC. (http://www.lyonbros.com)
 *
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 */
(function() {
	var Composer	=	{};
	var global	=	typeof(global) != 'undefined' ? global :
						typeof(window) != 'undefined' ? window :
							this;

	/**
	 * You must override this function in your app.
	 */
	Composer.sync	=	function(method, model, options) { return options.success(); };

    // an option to suppress those annoying warnings when overriding initialize and extend methods
    Composer.suppress_warnings = false;

	// a closure that returns incrementing integers. these will be unique across
	// the entire app since only one counter is instantiated
	Composer.cid	=	(function() {
		var counter	=	1;
		return function(inc) { return 'c'+counter++; };
	})();

	/**
	 * The events class provides bindings to objects (Models and Collections,
	 * mainly) and allows triggering of those events. For instance, a controller
	 * can bind its "removeItemFromView" function to its model's "destroy" event.
	 * Now when that model is destroyed, the destroyer doesn't have to remember to
	 * also trigger the "removeItemFromView" function, but it will happen
	 * automatically as a result of the binding.
	 *
	 * Note that this class is meant to be extended and doesn't provide much use on
	 * its own.
	 *
	 * Certain events are used by the framework itself:
	 *   Models:
	 *     "change" - called when a model's values are changed vie its set()
	 *       function.
	 *     "change:[key]" - called when [key] is changed under model's data. For
	 *       instance, if you did :
	 *         model.bind("change:name", myfn);
	 *         model.set({name: 'leonard'});    // <-- this will trigger the event
	 *     "destroy" - called when model.destroy() is called.
	 *     "error" - triggered when an error happens saving/reading/validating the
	 *       model
	 *   Collections:
	 *     "add" - Called when a model is added to a collection via
	 *       collection.add()
	 *     "clear" - Called when all models are cleared out of a via
	 *       collection.clear()
	 *     "reset" - Called when collection is reset with new model data via
	 *       collection.reset()
	 *     "remove" - Called when collection.remove() is used to remove a model
	 *       from the collection
	 *   Controllers:
	 *     "release" - Called when controller.release() is called to remove the
	 *       controller from the view.
	 *
	 * Note that the "all" event will bubble up from model to collection...when a
	 * model is added to a collection via collection.add(), the collection binds
	 * an 'all' event to that model so that any events that happen on that model
	 * will be triggered in the collection as well. This makes it easy for a
	 * controller to monitor changes on collections of items instead of each item
	 * individually.
	 */
	var Events	=	new Class({
		_events: {},
		_named_events: {},

		/**
		 * Bind a callback to a specific event for this object. Adds the callback to
		 * an array instead of replacing other callbacks, so many callbacks can exist
		 * under the same event for this object.
		 *
		 * Example: mymodel.bind("change", this.render.bind(this));
		 *
		 * Whenever mymodel is changed in any way, the "render" function for the
		 * current object (probably a controller in this instance) will be called.
		 */
		bind: function(ev, callback, callback_name)
		{
			if(typeof(ev) == 'object' && ev.length)
			{
				// it's an array, process each binding separately
				return ev.each(function(evname) {
					this.bind(evname, callback, callback_name);
				}, this);
			}
			callback_name || (callback_name = null);

			if(callback_name)
			{
				// prepend event type to callback name
				callback_name	=	ev+':'+callback_name;

				if(!this._named_events[callback_name])
				{
					// assign the callback into the named collection so it can be retrieved
					// later by name if required.
					this._named_events[callback_name]	=	callback;
				}
				else
				{
					// don't bother with duplicate event names
					return false;
				}
			}

			this._events[ev] || (this._events[ev] = []);
			if(!this._events[ev].contains(callback))
			{
				this._events[ev].push(callback);
			}

			return this;
		},

		/**
		 * Trigger an event for this object, which in turn runs all callbacks for that
		 * event WITH all parameters passed in to this function.
		 *
		 * For instance, you could do:
		 * mymodel.bind("destroy", this.removeFromView.bind(this));
		 * mymodel.trigger("destroy", "omg", "lol", "wtf");
		 *
		 * this.removeFromView will be called with the arguments "omg", "lol", "wtf".
		 *
		 * Note that any trigger event will also trigger the "all" event. the idea
		 * being that you can subscribe to anything happening on an object.
		 */
		trigger: function(ev)
		{
			var args	=	shallow_array_clone(Array.from(arguments));
			[ev, 'all'].each(function(type) {
				if(!this._events[type]) return;
				Array.clone(this._events[type]).each(function(callback) {
					callback.apply(this, (type == 'all') ? args : args.slice(1));
				}, this);
			}, this);

			return this;
		},

		/**
		 * Unbinds an event from the current object.
		 */
		unbind: function(ev, callback)
		{
			if(typeof(ev) == 'object' && ev.length)
			{
				// it's an array, process each item individually
				return ev.each(function(evname) {
					this.unbind(evname, callback);
				}, this);
			}

			if(typeof(ev) == 'undefined')
			{
				// no event passed, unbind everything
				this._events		=	{};
				this._named_events	=	{};
				return this;
			}

			if(typeof(this._events[ev]) == 'undefined' || this._events[ev].length == 0)
			{
				// event isn't bound
				return this;
			}

			if(typeof(callback) == 'string')
			{
				// load the function we assigned the name to and assign it to "callback",
				// also removing the named reference after we're done.
				callback	=	ev+':'+callback;
				var fn		=	this._named_events[callback];
				delete this._named_events[callback];
				var callback	=	fn;
			}

			if(!callback) return this;

			// remove all callback matches for the event type ev
			this._events[ev].erase(callback);

			return this;
		}
	});

	/**
	 * The base class is inherited by models, collections, and controllers. It
	 * provides some nice common functionality.
	 */
	var Base	=	new Class({
		/**
		 * Track this object's type. Useful for debugging, mainly
		 */
		__composer_type: 'base',
<commit_msg>Fixing/updating Event.unbind to remove all instances of an event if JUST the event name is passed. For isntance,<commit_after>/**
 * Composer.js is an MVC framework for creating and organizing javascript
 * applications. For documentation, please visit:
 *
 *     http://lyonbros.github.com/composer.js/
 *
 * -----------------------------------------------------------------------------
 *
 * Copyright (c) 2011, Lyon Bros Enterprises, LLC. (http://www.lyonbros.com)
 *
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 */
(function() {
	var Composer	=	{};
	var global	=	typeof(global) != 'undefined' ? global :
						typeof(window) != 'undefined' ? window :
							this;

	/**
	 * You must override this function in your app.
	 */
	Composer.sync	=	function(method, model, options) { return options.success(); };

    // an option to suppress those annoying warnings when overriding initialize and extend methods
    Composer.suppress_warnings = false;

	// a closure that returns incrementing integers. these will be unique across
	// the entire app since only one counter is instantiated
	Composer.cid	=	(function() {
		var counter	=	1;
		return function(inc) { return 'c'+counter++; };
	})();

	/**
	 * The events class provides bindings to objects (Models and Collections,
	 * mainly) and allows triggering of those events. For instance, a controller
	 * can bind its "removeItemFromView" function to its model's "destroy" event.
	 * Now when that model is destroyed, the destroyer doesn't have to remember to
	 * also trigger the "removeItemFromView" function, but it will happen
	 * automatically as a result of the binding.
	 *
	 * Note that this class is meant to be extended and doesn't provide much use on
	 * its own.
	 *
	 * Certain events are used by the framework itself:
	 *   Models:
	 *     "change" - called when a model's values are changed vie its set()
	 *       function.
	 *     "change:[key]" - called when [key] is changed under model's data. For
	 *       instance, if you did :
	 *         model.bind("change:name", myfn);
	 *         model.set({name: 'leonard'});    // <-- this will trigger the event
	 *     "destroy" - called when model.destroy() is called.
	 *     "error" - triggered when an error happens saving/reading/validating the
	 *       model
	 *   Collections:
	 *     "add" - Called when a model is added to a collection via
	 *       collection.add()
	 *     "clear" - Called when all models are cleared out of a via
	 *       collection.clear()
	 *     "reset" - Called when collection is reset with new model data via
	 *       collection.reset()
	 *     "remove" - Called when collection.remove() is used to remove a model
	 *       from the collection
	 *   Controllers:
	 *     "release" - Called when controller.release() is called to remove the
	 *       controller from the view.
	 *
	 * Note that the "all" event will bubble up from model to collection...when a
	 * model is added to a collection via collection.add(), the collection binds
	 * an 'all' event to that model so that any events that happen on that model
	 * will be triggered in the collection as well. This makes it easy for a
	 * controller to monitor changes on collections of items instead of each item
	 * individually.
	 */
	var Events	=	new Class({
		_events: {},
		_named_events: {},

		/**
		 * Bind a callback to a specific event for this object. Adds the callback to
		 * an array instead of replacing other callbacks, so many callbacks can exist
		 * under the same event for this object.
		 *
		 * Example: mymodel.bind("change", this.render.bind(this));
		 *
		 * Whenever mymodel is changed in any way, the "render" function for the
		 * current object (probably a controller in this instance) will be called.
		 */
		bind: function(ev, callback, callback_name)
		{
			if(typeof(ev) == 'object' && ev.length)
			{
				// it's an array, process each binding separately
				return ev.each(function(evname) {
					this.bind(evname, callback, callback_name);
				}, this);
			}
			callback_name || (callback_name = null);

			if(callback_name)
			{
				// prepend event type to callback name
				callback_name	=	ev+':'+callback_name;

				if(!this._named_events[callback_name])
				{
					// assign the callback into the named collection so it can be retrieved
					// later by name if required.
					this._named_events[callback_name]	=	callback;
				}
				else
				{
					// don't bother with duplicate event names
					return false;
				}
			}

			this._events[ev] || (this._events[ev] = []);
			if(!this._events[ev].contains(callback))
			{
				this._events[ev].push(callback);
			}

			return this;
		},

		/**
		 * Trigger an event for this object, which in turn runs all callbacks for that
		 * event WITH all parameters passed in to this function.
		 *
		 * For instance, you could do:
		 * mymodel.bind("destroy", this.removeFromView.bind(this));
		 * mymodel.trigger("destroy", "omg", "lol", "wtf");
		 *
		 * this.removeFromView will be called with the arguments "omg", "lol", "wtf".
		 *
		 * Note that any trigger event will also trigger the "all" event. the idea
		 * being that you can subscribe to anything happening on an object.
		 */
		trigger: function(ev)
		{
			var args	=	shallow_array_clone(Array.from(arguments));
			[ev, 'all'].each(function(type) {
				if(!this._events[type]) return;
				Array.clone(this._events[type]).each(function(callback) {
					callback.apply(this, (type == 'all') ? args : args.slice(1));
				}, this);
			}, this);

			return this;
		},

		/**
		 * Unbinds an event from the current object.
		 */
		unbind: function(ev, callback)
		{
			if(typeof(ev) == 'object' && ev.length)
			{
				// it's an array, process each item individually
				return ev.each(function(evname) {
					this.unbind(evname, callback);
				}, this);
			}

			if(typeof(ev) == 'undefined')
			{
				// no event passed, unbind everything
				this._events		=	{};
				this._named_events	=	{};
				return this;
			}

			if(typeof(this._events[ev]) == 'undefined' || this._events[ev].length == 0)
			{
				// event isn't bound
				return this;
			}

			if(typeof(callback) == 'undefined')
			{
				// no callback specified, remove all events of the given type
				Object.each(this._named_events, function(cb, ev_key) {
					// clear out all named events for this event type
					var match	=	ev_key.substr(0, ev.length + 1);
					if(ev+':' != match) return;
					delete this._named_events[ev_key];
				}, this);
				// empty out the event type
				this._events[ev].empty();
			}
			else
			{
				if(typeof(callback) == 'string')
				{
					// load the function we assigned the name to and assign it to "callback",
					// also removing the named reference after we're done.
					callback	=	ev+':'+callback;
					var fn		=	this._named_events[callback];
					delete this._named_events[callback];
					var callback	=	fn;
				}

				// remove all callback matches for the event type ev
				this._events[ev].erase(callback);
			}

			return this;
		}
	});

	/**
	 * The base class is inherited by models, collections, and controllers. It
	 * provides some nice common functionality.
	 */
	var Base	=	new Class({
		/**
		 * Track this object's type. Useful for debugging, mainly
		 */
		__composer_type: 'base',

{'fraction_non_alphanumeric': 0.12170889220069547, 'fraction_numerical': 0.0011354765453126109, 'mean_word_length': 2.779029230356664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2581107', 'n_tokens_mistral': 4743, 'n_tokens_neox': 3942, 'n_words': 1490}