<commit_before>"use strict";

/**
 * Class used as base for extending when a new controller is created.
 * @property view {meta.View} Default view controller is attached to.
 * @property name {string} Name of the controller.
 * @property flags {Boolean} All flags set to the controller.
 */
meta.class("meta.Controller",
{
	init: function() 
	{
		this.view = meta.createView("__ctrl__" + meta.cache.ctrlUniqueID++);

		if(this.onInit) {
			this.onInit();
		}
	},

	onInit: null,

	load: function() 
	{
		if(this.flags & this.Flag.LOADED) { return; }

		if((this.flags & this.Flag.FIRST_LOADED) === 0)
		{
			if(this.onFirstLoad) {
				this.onFirstLoad();
			}

			this.flags |= this.Flag.FIRST_LOADED;
		}

		if(this.onLoad) {
			this.onLoad();
		}

		meta.engine.controllersReady.push(this);
		meta.cache.view.attachView(this.view);
		
		this.flags |= this.Flag.LOADED;
	},

	unload: function()
	{
		if((this.flags & this.Flag.LOADED) === 0) { return; }

		if(this.onUnload) {
			this.onUnload();
		}

		if(this.onUpdate) {
			var buffer = meta.engine.controllersUpdate;
			var num = buffer.length;
			for(var n = 0; n < num; n++) {
				if(buffer[n] === this) {
					buffer.splice(n, 1);
					break;
				}
			}
		}

		meta.cache.view.detachView(this.view);
		this.flags &= ~(this.Flag.LOADED | this.Flag.READY);	
	},

	onFirstLoad: null,

	onLoad: null,

	onUnload: null,

	onFirstReady: null,

	onReady: null,	

	ready: function() 
	{
		if(this.flags & this.Flag.READY) { return; }

		if((this.flags & this.Flag.FIRST_READY) === 0)
		{
			if(this.onFirstReady) {
				this.onFirstReady();
			}

			this.flags |= this.Flag.FIRST_READY;
		}

		if(this.onReady) {
			this.onReady();
		}

		if(this.onUpdate) {
			meta.engine.controllersUpdate.push(this);
		}

		this.flags |= this.Flag.READY;<commit_msg>Added onTryLoad, onTryUnload, forceLoad, forceUnload for meta.Controller class.<commit_after>"use strict";

/**
 * Class used as base for extending when a new controller is created.
 * @property view {meta.View} Default view controller is attached to.
 * @property name {string} Name of the controller.
 * @property flags {Boolean} All flags set to the controller.
 */
meta.class("meta.Controller",
{
	init: function() 
	{
		this.view = meta.createView("__ctrl__" + meta.cache.ctrlUniqueID++);

		if(this.onInit) {
			this.onInit();
		}
	},

	onInit: null,

	load: function() 
	{
		if(this.flags & this.Flag.LOADED) { return; }

		if(this.onTryLoad) 
		{
			if(!this.onTryLoad()) {
				return;
			}
		}

		this.forceLoad();
	},

	forceLoad: function() 
	{
		if(this.flags & this.Flag.LOADED) { return; }

		if((this.flags & this.Flag.FIRST_LOADED) === 0)
		{
			if(this.onFirstLoad) {
				this.onFirstLoad();
			}

			this.flags |= this.Flag.FIRST_LOADED;
		}

		if(this.onLoad) {
			this.onLoad();
		}

		meta.engine.controllersReady.push(this);
		meta.cache.view.attachView(this.view);
		
		this.flags |= this.Flag.LOADED;
	},

	unload: function()
	{
		if((this.flags & this.Flag.LOADED) === 0) { return; }

		if(this.onTryUnload) 
		{
			if(!this.onTryUnload()) {
				return;
			}
		}

		this.forceUnload();
	},

	forceUnload: function()
	{
		if((this.flags & this.Flag.LOADED) === 0) { return; }
		
		if(this.onUnload) {
			this.onUnload();
		}

		if(this.onUpdate) {
			var buffer = meta.engine.controllersUpdate;
			var num = buffer.length;
			for(var n = 0; n < num; n++) {
				if(buffer[n] === this) {
					buffer.splice(n, 1);
					break;
				}
			}
		}

		meta.cache.view.detachView(this.view);
		this.flags &= ~(this.Flag.LOADED | this.Flag.READY);	
	},

	onTryLoad: null,

	onFirstLoad: null,

	onLoad: null,

	onTryUnload: null,

	onUnload: null,

	onFirstReady: null,

	onReady: null,	

	ready: function() 
	{
		if(this.flags & this.Flag.READY) { return; }

		if((this.flags & this.Flag.FIRST_READY) === 0)
		{
			if(this.onFirstReady) {
				this.onFirstReady();
			}

			this.flags |= this.Flag.FIRST_READY;
		}

		if(this.onReady) {
			this.onReady();
		}

		if(this.onUpdate) {
			meta.engine.controllersUpdate.push(this);
		}

		this.flags |= this.Flag.READY;
{'fraction_non_alphanumeric': 0.16621721010051482, 'fraction_numerical': 0.0026967393969110076, 'mean_word_length': 3.0117994100294987, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6465518', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1543, 'n_words': 279}