<commit_before>// TODO: resolve how loading will work
var Framework = Mast;
////////////////////////////////////////////////////////////////////////////

// TODO: disable debug mode
Framework.debug = true;

/**
 * This is the starting point to your Mast application. It runs multiple proccess that allow a
 * Mast application to run. You should grab templates and components with something like
 * Require.js before calling Framework.raise().
 *
 * @param  {Object}   options
 * @param  {Function} cb
 *
 * options example:
 * 	options = {
 * 		data: {
 * 			authenticated: false
 * 		},
 * 		templates: {
 *		 componentName: templateHTML
 *	  },
 *	  components: {
 *		 componentName: ComponentDefinition
 *	  }
 * 	}
 */
Framework.raise = function (options, cb) {

	// If only one arg is present, use options as callback if possible
	// If options are not defined, use an empty object
	if (!cb && _.isFunction(options)) {
		cb = options;
	}
	if (!_.isObject(options)) {
		options = {};
	}

	// If log is specified, use it, otherwise use the console
	if (options.log) {
		Framework.log = options.log;
		Framework.warn = options.log.warn;
		Framework.error = options.log.error;
		Framework.debug = Framework.debug ? options.log.debug : function () {};
	}
	else {
		Framework.log = Framework.isProduction ? function () {} : console.log.bind(console);
		Framework.warn = Framework.isProduction ? function () {} : console.warn.bind(console);
		Framework.error = Framework.isProduction ? function () {} : console.error.bind(console);
		Framework.debug = Framework.debug ? console.debug.bind(console) : function () {};
	}

	// Merge data into Framework.data
	_.extend(Framework.data, options.data || {});

	// Merge specified templates with Framework.templates
	_.extend(Framework.templates, options.templates || {});

	// If Mast.define() was used, build the list of components
	Framework._buildComponentDefinitions();

	// Merge specified components w/ Framework.components
	_.extend(Framework.components, options.components || {});

	// Back up each component definition before transforming it into a live prototype
	Framework.componentDefs = _.clone(Framework.components);




	// Wait until Framework core is ready
	Framework.ready(function () {

		// Collect any <script> tag templates on the page
		// and absorb them into Framework.templates
		_.extend(Framework.templates, collectTemplates());

		// Build actual prototypes for the components
		// (need the templates at this point to make this work)
		buildComponentPrototypes();


		// TODO: v2.5
		// ################################
		// Load any missing templates named in our components asynchronously

		// Determine dependencies by parsing HTML for regions

		// Find a flat list of all the top-level region components
		// (i.e. <region>s which are not inside other <region>s)
		// ################################


		// TODO: v2.3
		// ################################
		// For all regions, absorb implicit templates, identifying discovered regions as subcomponents

		// If no implicit template found, and either:
		// (1) no component with the same name is found, and no template with the same name is found
		// or (2) a component w/ the same name is found, but no template is specified
		// Then throw an error and ignore that region.

		// How will this work?

		// Of the stuff initially in the DOM, and starting with each top-level region,
		// descend to the leaf branches in the current tree, absorbing the implicit contents
		// from each of its child regions, until we reach a leaf.
		// ################################


		// TODO: v2.3
		// ################################
		// Only grab top-level regions, since implicit DOM parsing is enabled
		// ################################

		// Grab initial regions from DOM
		collectRegions();



		// Do the initial routing sequence
		// Look at the #fragment url and fire the global route event
		Framework.history.start();


		// TODO: v2.1
		// ################################
		// Fire the register event on all async endpoint collections/models
		//
		// This will let things like socket adapters make the initial connection
		// ################################

		// ################################
		// Trigger callback
		if (cb) cb();

	});



	// Iterate through component definitions, merge them with templates, and build actual prototypes
	function buildComponentPrototypes() {
		_.each(Framework.components, function (componentDef, componentKey) {

			// If component id is not explicitly set, use the componentKey
			if (!componentDef.id) componentDef.id = componentKey;

			// Validate that the component definition doesn't have any forbidden properties
			Framework.Component.prototype._validateDefinition(componentDef);

			// TODO: Validate that the component isn't named anything naughty
			// (can't think of anything that would cause problems at the moment)

			// Search templates
			var template = Framework.templates[componentDef.id];

			// If no match for component was found in templates, issue a warning
			// (unless this is the global app component, in which case it's fine)
			// if (!template && componentDef.id !== 'App') {
			if (!template) {
				return Framework.warn(componentDef.id + ' :: No template found for component!');
			}

			// Save reference to template in component prototype
			Framework.debug(componentDef.id + ' :: Pairing component with template...');
			componentDef.template = template;

			// Translate right-hand shorthand for top-level keys and events object
			componentDef = objMap(componentDef, translateShorthand);
			if (componentDef.events) {
				componentDef.events = objMap(componentDef.events, translateShorthand);
			}

			// Go ahead and turn the definition into a real component prototype
			var componentPrototype = Framework.Component.extend(componentDef);

			// Discover subscriptions
			componentPrototype.prototype.subscriptions = {};

			// Iterate through each property on this component prototype
			_.each(componentPrototype.prototype, function (handler, key) {
				if (key.match(/^(%|#|~)/)) {
					if (!_.isString(handler)) {
            throw new Error(componentDef.id + ':: Invalid listener for subscription: ' + key +'. Define your callback with an anonymous function instead of a string.');
          }
					if (!_.isFunction(handler)) {<commit_msg>fixed negation error on checking for string handler<commit_after>// TODO: resolve how loading will work
var Framework = Mast;
////////////////////////////////////////////////////////////////////////////

// TODO: disable debug mode
Framework.debug = true;

/**
 * This is the starting point to your Mast application. It runs multiple proccess that allow a
 * Mast application to run. You should grab templates and components with something like
 * Require.js before calling Framework.raise().
 *
 * @param  {Object}   options
 * @param  {Function} cb
 *
 * options example:
 * 	options = {
 * 		data: {
 * 			authenticated: false
 * 		},
 * 		templates: {
 *		 componentName: templateHTML
 *	  },
 *	  components: {
 *		 componentName: ComponentDefinition
 *	  }
 * 	}
 */
Framework.raise = function (options, cb) {

	// If only one arg is present, use options as callback if possible
	// If options are not defined, use an empty object
	if (!cb && _.isFunction(options)) {
		cb = options;
	}
	if (!_.isObject(options)) {
		options = {};
	}

	// If log is specified, use it, otherwise use the console
	if (options.log) {
		Framework.log = options.log;
		Framework.warn = options.log.warn;
		Framework.error = options.log.error;
		Framework.debug = Framework.debug ? options.log.debug : function () {};
	}
	else {
		Framework.log = Framework.isProduction ? function () {} : console.log.bind(console);
		Framework.warn = Framework.isProduction ? function () {} : console.warn.bind(console);
		Framework.error = Framework.isProduction ? function () {} : console.error.bind(console);
		Framework.debug = Framework.debug ? console.debug.bind(console) : function () {};
	}

	// Merge data into Framework.data
	_.extend(Framework.data, options.data || {});

	// Merge specified templates with Framework.templates
	_.extend(Framework.templates, options.templates || {});

	// If Mast.define() was used, build the list of components
	Framework._buildComponentDefinitions();

	// Merge specified components w/ Framework.components
	_.extend(Framework.components, options.components || {});

	// Back up each component definition before transforming it into a live prototype
	Framework.componentDefs = _.clone(Framework.components);




	// Wait until Framework core is ready
	Framework.ready(function () {

		// Collect any <script> tag templates on the page
		// and absorb them into Framework.templates
		_.extend(Framework.templates, collectTemplates());

		// Build actual prototypes for the components
		// (need the templates at this point to make this work)
		buildComponentPrototypes();


		// TODO: v2.5
		// ################################
		// Load any missing templates named in our components asynchronously

		// Determine dependencies by parsing HTML for regions

		// Find a flat list of all the top-level region components
		// (i.e. <region>s which are not inside other <region>s)
		// ################################


		// TODO: v2.3
		// ################################
		// For all regions, absorb implicit templates, identifying discovered regions as subcomponents

		// If no implicit template found, and either:
		// (1) no component with the same name is found, and no template with the same name is found
		// or (2) a component w/ the same name is found, but no template is specified
		// Then throw an error and ignore that region.

		// How will this work?

		// Of the stuff initially in the DOM, and starting with each top-level region,
		// descend to the leaf branches in the current tree, absorbing the implicit contents
		// from each of its child regions, until we reach a leaf.
		// ################################


		// TODO: v2.3
		// ################################
		// Only grab top-level regions, since implicit DOM parsing is enabled
		// ################################

		// Grab initial regions from DOM
		collectRegions();



		// Do the initial routing sequence
		// Look at the #fragment url and fire the global route event
		Framework.history.start();


		// TODO: v2.1
		// ################################
		// Fire the register event on all async endpoint collections/models
		//
		// This will let things like socket adapters make the initial connection
		// ################################

		// ################################
		// Trigger callback
		if (cb) cb();

	});



	// Iterate through component definitions, merge them with templates, and build actual prototypes
	function buildComponentPrototypes() {
		_.each(Framework.components, function (componentDef, componentKey) {

			// If component id is not explicitly set, use the componentKey
			if (!componentDef.id) componentDef.id = componentKey;

			// Validate that the component definition doesn't have any forbidden properties
			Framework.Component.prototype._validateDefinition(componentDef);

			// TODO: Validate that the component isn't named anything naughty
			// (can't think of anything that would cause problems at the moment)

			// Search templates
			var template = Framework.templates[componentDef.id];

			// If no match for component was found in templates, issue a warning
			// (unless this is the global app component, in which case it's fine)
			// if (!template && componentDef.id !== 'App') {
			if (!template) {
				return Framework.warn(componentDef.id + ' :: No template found for component!');
			}

			// Save reference to template in component prototype
			Framework.debug(componentDef.id + ' :: Pairing component with template...');
			componentDef.template = template;

			// Translate right-hand shorthand for top-level keys and events object
			componentDef = objMap(componentDef, translateShorthand);
			if (componentDef.events) {
				componentDef.events = objMap(componentDef.events, translateShorthand);
			}

			// Go ahead and turn the definition into a real component prototype
			var componentPrototype = Framework.Component.extend(componentDef);

			// Discover subscriptions
			componentPrototype.prototype.subscriptions = {};

			// Iterate through each property on this component prototype
			_.each(componentPrototype.prototype, function (handler, key) {
				if (key.match(/^(%|#|~)/)) {
					if (_.isString(handler)) {
            throw new Error(componentDef.id + ':: Invalid listener for subscription: ' + key +'. Define your callback with an anonymous function instead of a string.');
          }
					if (!_.isFunction(handler)) {
{'fraction_non_alphanumeric': 0.15367134237128752, 'fraction_numerical': 0.001567275291905023, 'mean_word_length': 3.3467302452316074, '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': '6833018', 'n_tokens_mistral': 3643, 'n_tokens_neox': 3176, 'n_words': 1231}