<commit_before>
var 	   _ = require("alloy/underscore")._,
	Backbone = require("alloy/backbone"),
	STR = require('alloy/string');
	
exports._ = _;
exports.Backbone = Backbone;

// TODO: we might want to eliminate this as all sync operations can be handles
//       in the adapter-specific code
Backbone.Collection.notify = _.extend({}, Backbone.Events);

Backbone.sync = function(method, model, opts) {
	// Ti.API.info("sync called with method="+method+", model="+JSON.stringify(model)+", opts="+JSON.stringify(opts));
	// Ti.API.info("config => "+JSON.stringify(model.config));
	
	var m = (model.config || {});
	var type = (m.adapter ? m.adapter.type : null) || 'sql';

	require('alloy/sync/'+type).sync(model,method,opts);

	// TODO: we might want to eliminate this as all sync operations can be handles
	//       in the adapter-specific code
	Backbone.Collection.notify.trigger('sync', {method:method,model:model});
};

exports.M = function(name,config,modelFn,migrations) {
    var type = (config.adapter ? config.adapter.type : null) || 'sql';
    var adapter = require('alloy/sync/'+type);
    var extendObj = {
		defaults: config.defaults,
		validate: function(attrs) {
			if (typeof __validate !== 'undefined') {
				if (_.isFunction(__validate)) {
					for (var k in attrs) {
						var t = __validate(k, attrs[k]);
						if (!t) {
							return "validation failed for: "+k;
						}
					}
				}
			}
		}
	};

	// cosntruct the model based on the current adapter type
	if (migrations) { extendObj.migrations = migrations; }
    if (_.isFunction(adapter.beforeModelCreate)) { config = adapter.beforeModelCreate(config) || config; }
	var Model = Backbone.Model.extend(extendObj);
	config.Model = Model; // needed for fetch operations to initialize the collection from persistent store
	config.data = {}; // for localStorage or case where entire collection is needed to maintain store
	Model.prototype.config = config;
	if (_.isFunction(adapter.afterModelCreate)) { adapter.afterModelCreate(Model); }
	
	// execute any custom scripts on the model
	Model = modelFn(Model) || Model;
	
	return Model;
};

exports.A = function(t,type,parent) {
	_.extend(t,Backbone.Events);
	
	(function() {
		
		// we are going to wrap addEventListener and removeEventListener
		// with on, off so we can use the Backbone events
		var al = t.addEventListener,
			rl = t.removeEventListener,
			oo = t.on,
			of = t.off,
			tg = t.trigger,
		   cbs = [],
		   ctx = {};

		t.on = function(e,cb,context) {
			var wcb = function(evt) {
				try {
					_.bind(tg,ctx,e,evt)();
				}
				catch(E) {
					Ti.API.error("Error triggering '"+e+"' event: "+E);
				}
			};
			cbs[cb]=wcb;

			if (OS_IOS) {
				al(e, wcb);
			} else {
				al.call(t, e, wcb);
			}

			_.bind(oo,ctx,e,cb,context)();
		};

		t.off = function(e,cb,context) {
			var f = cbs[cb];
			if (f) {
				_.bind(of,ctx,e,cb,context)();

				if (OS_IOS) {
					rl(e, f);
				} else {
					rl.call(t, e, f);
				}
				
				delete cbs[cb];
				f = null;
			}
		};
		
	})();
	
	return t;
}

exports.getWidget = function(id) {
	return require('alloy/widgets/' + id + '/components/widget');
}

exports.getComponent = function(name) {
	return require('alloy/components/' + name);
}

exports.getModel = function(name) {
	return require('alloy/models/' + STR.ucfirst(name)).Model;
}

exports.Collections = function(name) {
	return require('alloy/models/' + STR.ucfirst(name)).Collection;
}<commit_msg>fixed getCollection()<commit_after>
var 	   _ = require("alloy/underscore")._,
	Backbone = require("alloy/backbone"),
	STR = require('alloy/string');
	
exports._ = _;
exports.Backbone = Backbone;

// TODO: we might want to eliminate this as all sync operations can be handles
//       in the adapter-specific code
Backbone.Collection.notify = _.extend({}, Backbone.Events);

Backbone.sync = function(method, model, opts) {
	// Ti.API.info("sync called with method="+method+", model="+JSON.stringify(model)+", opts="+JSON.stringify(opts));
	// Ti.API.info("config => "+JSON.stringify(model.config));
	
	var m = (model.config || {});
	var type = (m.adapter ? m.adapter.type : null) || 'sql';

	require('alloy/sync/'+type).sync(model,method,opts);

	// TODO: we might want to eliminate this as all sync operations can be handles
	//       in the adapter-specific code
	Backbone.Collection.notify.trigger('sync', {method:method,model:model});
};

exports.M = function(name,config,modelFn,migrations) {
    var type = (config.adapter ? config.adapter.type : null) || 'sql';
    var adapter = require('alloy/sync/'+type);
    var extendObj = {
		defaults: config.defaults,
		validate: function(attrs) {
			if (typeof __validate !== 'undefined') {
				if (_.isFunction(__validate)) {
					for (var k in attrs) {
						var t = __validate(k, attrs[k]);
						if (!t) {
							return "validation failed for: "+k;
						}
					}
				}
			}
		}
	};

	// cosntruct the model based on the current adapter type
	if (migrations) { extendObj.migrations = migrations; }
    if (_.isFunction(adapter.beforeModelCreate)) { config = adapter.beforeModelCreate(config) || config; }
	var Model = Backbone.Model.extend(extendObj);
	config.Model = Model; // needed for fetch operations to initialize the collection from persistent store
	config.data = {}; // for localStorage or case where entire collection is needed to maintain store
	Model.prototype.config = config;
	if (_.isFunction(adapter.afterModelCreate)) { adapter.afterModelCreate(Model); }
	
	// execute any custom scripts on the model
	Model = modelFn(Model) || Model;
	
	return Model;
};

exports.A = function(t,type,parent) {
	_.extend(t,Backbone.Events);
	
	(function() {
		
		// we are going to wrap addEventListener and removeEventListener
		// with on, off so we can use the Backbone events
		var al = t.addEventListener,
			rl = t.removeEventListener,
			oo = t.on,
			of = t.off,
			tg = t.trigger,
		   cbs = [],
		   ctx = {};

		t.on = function(e,cb,context) {
			var wcb = function(evt) {
				try {
					_.bind(tg,ctx,e,evt)();
				}
				catch(E) {
					Ti.API.error("Error triggering '"+e+"' event: "+E);
				}
			};
			cbs[cb]=wcb;

			if (OS_IOS) {
				al(e, wcb);
			} else {
				al.call(t, e, wcb);
			}

			_.bind(oo,ctx,e,cb,context)();
		};

		t.off = function(e,cb,context) {
			var f = cbs[cb];
			if (f) {
				_.bind(of,ctx,e,cb,context)();

				if (OS_IOS) {
					rl(e, f);
				} else {
					rl.call(t, e, f);
				}
				
				delete cbs[cb];
				f = null;
			}
		};
		
	})();
	
	return t;
}

exports.getWidget = function(id) {
	return require('alloy/widgets/' + id + '/components/widget');
}

exports.getComponent = function(name) {
	return require('alloy/components/' + name);
}

exports.getModel = function(name) {
	return require('alloy/models/' + STR.ucfirst(name)).Model;
}

exports.getCollection = function(name) {
	return require('alloy/models/' + STR.ucfirst(name)).Collection;
}
{'fraction_non_alphanumeric': 0.15979081929110983, 'fraction_numerical': 0.0, 'mean_word_length': 3.2870485678704857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1410796', 'n_tokens_mistral': 2605, 'n_tokens_neox': 2291, 'n_words': 555}