<commit_before>/*global define*/

define([
	'jquery',
	'underscore',
	'handlebars',
	'router',
	'epoxy',
	'loomutils/helpers/loader',
	'loomutils/helpers/route-callback',
	'loomutils/models/view',
	'loomutils/helpers/logger'
], function ($, _, Handlebars, router, Epoxy, Loader, RouteCallback, ViewModel, logger) {

	'use strict';

	var V = Epoxy.View.extend({

		/**
		 * Reference to the router
		 * @type {Object}
		 */
		router: router,


		/**
		 * Loader helper
		 * @type {Object}
		 */
		_loader: {},


		/**
		 * Model holds state info we want to be able to trigger events on
		 * @type {Model}
		 */
		viewModel: undefined,


		/**
		 * Default template
		 * @type {Function}
		 */
		template: Handlebars.compile(''),


		/**
		 * Child views
		 * @type {Array}
		 */
		children: [],


		/**
		 * Routes
		 * @type {Object}
		 */
		routes: {},


		/**
		 * Event listeners on objects
		 * @type {Object}
		 */
		listeners: {},


		/**
		 * DOM events
		 * @type {Object}
		 */
		events: {
			'click [data-link]': 'linkElement'
		},


		/**
		 * Initialize
		 */
		initialize: function () {

			// New model instance
			this.viewModel = new ViewModel();


			// Listen to viewModel changes
			this.listenTo(this.viewModel, 'change:active', this.onActiveChange);
			this.listenTo(this.viewModel.get('children'), 'change:active', this.onChildActiveChange);


			// New loader instance
			this._setupLoader();


			// New child model instance
			this._setupChildrenCollection();


			// Add route listeners
			this._setupRoutes();


			// Add object listeners
			this._setupListeners();


			// Listen for load events
			this.on('loaderLoaded childrenLoaded', this.onComponentLoaded);


			// When we render, load the rendered content
			this.on('rendered', this.load);
		},


		/**
		 * Render the view
		 */
		render: function () {

			// Remove event bindings
			this.undelegateEvents();


			// Render the template
			this.$el.html('').append(this.template(this.getData()));


			// Readd events
			this.delegateEvents();


			// Render the children
			this.renderChildren();


			// Apply epoxy view bindings
			this.applyBindings();


			// Dispatch a rendered event
			this.viewModel.set('rendered', true);
			this.trigger('rendered');
		},


		/**
		 * Load assets and dispatch a load event when done
		 */
		load: function () {

			this._loader.addElement(this.$el);
			this._loader.load();
		},


		/**
		 * Route to one of the children
		 * @param {String} id
		 * @param {String} route
		 * @param {Object} params
		 */
		routeTo: function (id, route, params) {

			try {
				var view = this.getChildView(id);
				view.routes[route].call(view, params);
			}
			catch (e) {
				console.log('Failed to route "' + route + '" on child "' + id + '"');
			}
		},


		/**
		 * Render child views
		 */
		renderChildren: function () {

			// Reset the number of children loaded
			this.viewModel.get('children').loadedCount = 0;


			// Loop through all of the children
			this.viewModel.get('children').each(this.renderChild, this);
		},


		/**
		 * Render a child view and append it
		 * @param {Object} child
		 */
		renderChild: function (child) {

			// Get the view
			var view = child.get('view'),
				target = child.get('target');


			// Render the child
			if (!child.get('rendered')) {
				view.render();
			}


			// If we're not loaded yet, wait to add the view until we are
			if (!child.get('loaded')) {
				return this.listenToOnce(child, 'loaded', this.renderChild);
			}


			// Place in the target area if we have one
			if (target) {

				// Are we supposed to replace the target?
				if (child.get('replace')) {
					this.$(target).replaceWith(view.$el);
				}
				else {
					this.$(target).append(view.$el);
				}
			}
			// Fallback placements
			else {

				// Get possible target areas
				var dataTarget = this.$('[data-child-area=' + view.id + ']'),
					childTarget = this.$('.children');


				// Place the child in the right area
				if (dataTarget.length) {
					dataTarget.append(view.$el);
				}
				else if (childTarget.length) {
					childTarget.append(view.$el);
				}
				else {
					this.$el.append(view.$el);
				}
			}
		},


		/**
		 * Get data from our collection or model
		 * @return {Mixed}
		 */
		getData: function () {

			if (this.collection) {
				return this.collection.toJSON();
			}
			else if (this.model) {
				return this.model.toJSON();
			}

			return {};
		},<commit_msg>default to recursive data getting<commit_after>/*global define*/

define([
	'jquery',
	'underscore',
	'handlebars',
	'router',
	'epoxy',
	'loomutils/helpers/loader',
	'loomutils/helpers/route-callback',
	'loomutils/models/view',
	'loomutils/helpers/logger'
], function ($, _, Handlebars, router, Epoxy, Loader, RouteCallback, ViewModel, logger) {

	'use strict';

	var V = Epoxy.View.extend({

		/**
		 * Reference to the router
		 * @type {Object}
		 */
		router: router,


		/**
		 * Loader helper
		 * @type {Object}
		 */
		_loader: {},


		/**
		 * Model holds state info we want to be able to trigger events on
		 * @type {Model}
		 */
		viewModel: undefined,


		/**
		 * Default template
		 * @type {Function}
		 */
		template: Handlebars.compile(''),


		/**
		 * Child views
		 * @type {Array}
		 */
		children: [],


		/**
		 * Routes
		 * @type {Object}
		 */
		routes: {},


		/**
		 * Event listeners on objects
		 * @type {Object}
		 */
		listeners: {},


		/**
		 * DOM events
		 * @type {Object}
		 */
		events: {
			'click [data-link]': 'linkElement'
		},


		/**
		 * Initialize
		 */
		initialize: function () {

			// New model instance
			this.viewModel = new ViewModel();


			// Listen to viewModel changes
			this.listenTo(this.viewModel, 'change:active', this.onActiveChange);
			this.listenTo(this.viewModel.get('children'), 'change:active', this.onChildActiveChange);


			// New loader instance
			this._setupLoader();


			// New child model instance
			this._setupChildrenCollection();


			// Add route listeners
			this._setupRoutes();


			// Add object listeners
			this._setupListeners();


			// Listen for load events
			this.on('loaderLoaded childrenLoaded', this.onComponentLoaded);


			// When we render, load the rendered content
			this.on('rendered', this.load);
		},


		/**
		 * Render the view
		 */
		render: function () {

			// Remove event bindings
			this.undelegateEvents();


			// Render the template
			this.$el.html('').append(this.template(this.getData()));


			// Readd events
			this.delegateEvents();


			// Render the children
			this.renderChildren();


			// Apply epoxy view bindings
			this.applyBindings();


			// Dispatch a rendered event
			this.viewModel.set('rendered', true);
			this.trigger('rendered');
		},


		/**
		 * Load assets and dispatch a load event when done
		 */
		load: function () {

			this._loader.addElement(this.$el);
			this._loader.load();
		},


		/**
		 * Route to one of the children
		 * @param {String} id
		 * @param {String} route
		 * @param {Object} params
		 */
		routeTo: function (id, route, params) {

			try {
				var view = this.getChildView(id);
				view.routes[route].call(view, params);
			}
			catch (e) {
				console.log('Failed to route "' + route + '" on child "' + id + '"');
			}
		},


		/**
		 * Render child views
		 */
		renderChildren: function () {

			// Reset the number of children loaded
			this.viewModel.get('children').loadedCount = 0;


			// Loop through all of the children
			this.viewModel.get('children').each(this.renderChild, this);
		},


		/**
		 * Render a child view and append it
		 * @param {Object} child
		 */
		renderChild: function (child) {

			// Get the view
			var view = child.get('view'),
				target = child.get('target');


			// Render the child
			if (!child.get('rendered')) {
				view.render();
			}


			// If we're not loaded yet, wait to add the view until we are
			if (!child.get('loaded')) {
				return this.listenToOnce(child, 'loaded', this.renderChild);
			}


			// Place in the target area if we have one
			if (target) {

				// Are we supposed to replace the target?
				if (child.get('replace')) {
					this.$(target).replaceWith(view.$el);
				}
				else {
					this.$(target).append(view.$el);
				}
			}
			// Fallback placements
			else {

				// Get possible target areas
				var dataTarget = this.$('[data-child-area=' + view.id + ']'),
					childTarget = this.$('.children');


				// Place the child in the right area
				if (dataTarget.length) {
					dataTarget.append(view.$el);
				}
				else if (childTarget.length) {
					childTarget.append(view.$el);
				}
				else {
					this.$el.append(view.$el);
				}
			}
		},


		/**
		 * Get data from our collection or model
		 * @return {Mixed}
		 */
		getData: function () {

			if (this.collection) {
				return this.collection.toJSON({
					recursive: true
				});
			}
			else if (this.model) {
				return this.model.toJSON({
					recursive: true
				});
			}

			return {};
		},
{'fraction_non_alphanumeric': 0.1546875, 'fraction_numerical': 0.0002232142857142857, 'mean_word_length': 2.4746025591314464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1314379', 'n_tokens_mistral': 3574, 'n_tokens_neox': 2804, 'n_words': 722}