<commit_before>/**
 * @class  Event
 * @author  <NAME> <<EMAIL>>
 * An event manager completely disassociated for Ti.App.addEventListener / Ti.App.removeEventListener
 */

/**
 * @type {Object}
 */
var config = _.extend({}, Alloy.CFG.T.events);
exports.config = config;

var __Events = {};


/**
 * Adds the specified callback as an event listener for the named events
 *
 * @param {String}   key  The unique key
 * @param {Function} cb The callback
 */
function add(key, cb) {
	if (key in __Events) __Events[key].push(cb);
	else __Events[key] = [cb];
}
exports.add = add;

/**
 * @method on
 * @inheritDoc #add
 * Alias for {@link #add}
 */
exports.on = add;

/**
 * Removes the specified callback as an event listener for the named event.
 *
 * If no callback is specified, all listener for that key were removed
 *
 * @param {String}   key  The unique key
 * @param {Function} [cb] The callback
 */
function rem(key, cb) {
	if (!(key in __Events)) return;

	if (_.isFunction(cb)) {
		_.each(__Events[key], function(fun, i){
			if (fun===cb) __Events[key].splice(i);
		});
	} else {
		delete __Events[key];
	}
}
exports.rem = rem;

/**
 * @method off
 * @inheritDoc #rem
 * Alias for  {@link #off}
 */
exports.off = rem;


/**
 * Shortcut for Event.off(key); Event.on(key, cb);
 *
 * @param  {String}   key The unique key
 * @param  {Function} cb  The callback
 */
function remThenAdd(key, cb) {
	rem(key);
	add(key, cb);
}
exports.remThenAdd = remThenAdd;

/**
 * @method offThenOn
 * @inheritDoc #remThenAdd
 * Alias for  {@link #off}
 */
exports.offThenOn = remThenAdd;


/**
 * Fires a synthesized event to any registered listeners.
 *
 * @param  {String} 		key  		The unique key
 * @param  {Arguments}	[...] 	The arguments to pass to the event
 */
function fire() {
	var key = Array.prototype.shift.call(arguments);
	if (!(key in __Events)) {
		Ti.API.warn("Events: No listener found for "+key);
	}<commit_msg>Documentation fixing<commit_after>/**
 * @class  Event
 * @author  <NAME> <<EMAIL>>
 * An event manager completely disassociated for Ti.App.addEventListener / Ti.App.removeEventListener
 */

/**
 * @type {Object}
 */
var config = _.extend({}, Alloy.CFG.T.events);
exports.config = config;

var __Events = {};


/**
 * Adds the specified callback as an event listener for the named events
 *
 * @param {String}   key  The unique key
 * @param {Function} cb The callback
 */
function add(key, cb) {
	if (key in __Events) __Events[key].push(cb);
	else __Events[key] = [cb];
}
exports.add = add;

/**
 * @method on
 * @inheritDoc #add
 * Alias for {@link #add}
 */
exports.on = add;

/**
 * Removes the specified callback as an event listener for the named event.
 *
 * If no callback is specified, all listener for that key were removed
 *
 * @param {String}   key  The unique key
 * @param {Function} [cb] The callback
 */
function rem(key, cb) {
	if (!(key in __Events)) return;

	if (_.isFunction(cb)) {
		_.each(__Events[key], function(fun, i){
			if (fun===cb) __Events[key].splice(i);
		});
	} else {
		delete __Events[key];
	}
}
exports.rem = rem;

/**
 * @method off
 * @inheritDoc #rem
 * Alias for  {@link #off}
 */
exports.off = rem;


/**
 * Shortcut for Event.off(key); Event.on(key, cb);
 *
 * @param  {String}   key The unique key
 * @param  {Function} cb  The callback
 */
function remThenAdd(key, cb) {
	rem(key);
	add(key, cb);
}
exports.remThenAdd = remThenAdd;

/**
 * @method offThenOn
 * @inheritDoc #remThenAdd
 * Alias for  {@link #off}
 */
exports.offThenOn = remThenAdd;


/**
 * Fires a synthesized event to any registered listeners.
 *
 * @param  {String} 		key  		The unique key
 * @param  {Arguments}	args 		The arguments to pass to the event
 */
function fire() {
	var key = Array.prototype.shift.call(arguments);
	if (!(key in __Events)) {
		Ti.API.warn("Events: No listener found for "+key);
	}
{'fraction_non_alphanumeric': 0.15386618068211402, 'fraction_numerical': 0.0, 'mean_word_length': 3.45707656612529, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2285744', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1304, 'n_words': 418}