<commit_before>'use strict';

// ## LRSView
// View class. Provides outlets, actions, templates, nesting etc.
class LRSView extends lrs.LRSObject {
	
	// ### `static` parseTemplates
	// Collect all templates from the document. Must be called once, before view initialisation.
	
	static parseTemplates() {
		
		if (this.templates) return
		
		this.templates = {}
		
		// Go over all elements containing templates.
		for (let templateContainerEl of Array.from(document.querySelectorAll('.templates'))) {
			
			// Remove it from the DOM first.
			templateContainerEl.parentNode.removeChild(templateContainerEl)
			
			// Create a new element and copy the container's HTML into it to create a DOM structure (in case it was passed as a string, e.g. in script tag).
			let templateContainerHTMLEl = document.createElement('div')
			templateContainerHTMLEl.innerHTML = templateContainerEl.innerHTML
			
			// Iterate all the children (templates)
			for (let templateEl of Array.from(templateContainerHTMLEl.children)) {
				
				// If no data-template attribute exists skip this element.
				if (!templateEl.hasAttribute('data-template')) continue
				
				// Get the name.
				let name = templateEl.getAttribute('data-template')
				// Remove the data-template attribute.
				templateEl.removeAttribute('data-template')
				// Save the HTML in @templates.
				this.templates[name] = templateEl.outerHTML
				
			}
			
			
		}
		
	}

	constructor(el, options) {
		
		super(options)
		
		this._listeners = []
		
		this.delegateAction = this.delegateAction.bind(this)
		
		// Check to see if we need to load a template and whether we can.
		if (this.options.template && (!el || el.children.length === 0)) {
			
			// Yes; load it.
			this._loadTemplate()
			
			// Put it in the DOM if we are there already.
			if (el && el.parentNode) {
				el.parentNode.replaceChild(this.el, el)
			}
			
		} else {
			
			// No; just set our el.
			this.el = el
			
		}
		
		this.hidden = this.el.classList.contains('hidden')
		this.enabled = !this.el.classList.contains('disabled')
		
		this._createViews()
		this._createOutlets()
		this._createActions()

		return this

	}
	
	// ### `private` loadTemplate
	// Create our el from the template defined in options.
	_loadTemplate() {
		
		var el = document.createElement('div')
		el.innerHTML = this.constructor.templates[this.options.template]
		this.el = el.firstChild
		
		return this
		
	}<commit_msg>Allow delaying of subview, outlet and action creation/processing.<commit_after>'use strict';

// ## LRSView
// View class. Provides outlets, actions, templates, nesting etc.
class LRSView extends lrs.LRSObject {
	
	// ### `static` parseTemplates
	// Collect all templates from the document. Must be called once, before view initialisation.
	
	static parseTemplates() {
		
		if (this.templates) return
		
		this.templates = {}
		
		// Go over all elements containing templates.
		for (let templateContainerEl of Array.from(document.querySelectorAll('.templates'))) {
			
			// Remove it from the DOM first.
			templateContainerEl.parentNode.removeChild(templateContainerEl)
			
			// Create a new element and copy the container's HTML into it to create a DOM structure (in case it was passed as a string, e.g. in script tag).
			let templateContainerHTMLEl = document.createElement('div')
			templateContainerHTMLEl.innerHTML = templateContainerEl.innerHTML
			
			// Iterate all the children (templates)
			for (let templateEl of Array.from(templateContainerHTMLEl.children)) {
				
				// If no data-template attribute exists skip this element.
				if (!templateEl.hasAttribute('data-template')) continue
				
				// Get the name.
				let name = templateEl.getAttribute('data-template')
				// Remove the data-template attribute.
				templateEl.removeAttribute('data-template')
				// Save the HTML in @templates.
				this.templates[name] = templateEl.outerHTML
				
			}
			
			
		}
		
	}

	constructor(el, options) {
		
		super(options)
		
		this._listeners = []
		
		this.delegateAction = this.delegateAction.bind(this)
		
		// Check to see if we need to load a template and whether we can.
		if (this.options.template && (!el || el.children.length === 0)) {
			
			// Yes; load it.
			this._loadTemplate()
			
			// Put it in the DOM if we are there already.
			if (el && el.parentNode) {
				el.parentNode.replaceChild(this.el, el)
			}
			
		} else {
			
			// No; just set our el.
			this.el = el
			
		}
		
		this.hidden = this.el.classList.contains('hidden')
		this.enabled = !this.el.classList.contains('disabled')
		
		if (!options || options.delayDomConnectionCreation !== true) this.createDomConnections()

		return this

	}
	
	createDomConnections() {
		
		if (this._domConnectionsCreated) throw new Error('DOM connections may only be create once.')
		
		this._domConnectionsCreated = true
		
		this._createViews()
		this._createOutlets()
		this._createActions()
		
	}
	
	// ### `private` loadTemplate
	// Create our el from the template defined in options.
	_loadTemplate() {
		
		var el = document.createElement('div')
		el.innerHTML = this.constructor.templates[this.options.template]
		this.el = el.firstChild
		
		return this
		
	}
{'fraction_non_alphanumeric': 0.10783179012345678, 'fraction_numerical': 0.00038580246913580245, 'mean_word_length': 3.028749028749029, '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': '4499087', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1456, 'n_words': 442}