packages/moon/src/executor/executor.js
function executeCreate(node) {
	let element;
	let children = [];

	if (node.type === types.text) {
		// Create a text node using the text content from the default key.
		element = document.createTextNode(node.data[""]);
	} else {
		const nodeData = node.data;

		// Create a DOM element.
		element = document.createElement(node.name);

		// Set data, events, and attributes.
		for (let key in nodeData) {
			const value = nodeData[key];

			if (key[0] === "@") {
				let MoonEvents = element.MoonEvents;

				if (MoonEvents === undefined) {
					MoonEvents = element.MoonEvents = {
						[key]: value
					};
				} else {
					MoonEvents[key] = value;
				}

				element.addEventListener(key.slice(1), ($event) => {
					MoonEvents[key]($event);
				});
			} else if (key !== "children" && value !== false) {
				element.setAttribute(key, value);
			}
		}

		// Recursively append children.
		const nodeDataChildren = nodeData.children;

		for (let i = 0; i < nodeDataChildren.length; i++) {
			const childOld = executeCreate(nodeDataChildren[i]);

			element.appendChild(childOld.element);
			children.push(childOld);
		}
	}

	// Return an old node with a reference to the immutable node and mutable
	// element. This is to help performance and allow static nodes to be reused.
	return {
		element,
		node,
		children
	};
}
function executeCreate(node) {
	let element;
	let children = [];

	if (node.type === types.text) {
		// Create a text node using the text content from the default key.
		element = document.createTextNode(node.data[""]);
	} else {
		const nodeData = node.data;

		// Create a DOM element.
		element = document.createElement(node.name);

		// Set data, events, and attributes.
		for (let key in nodeData) {
			const value = nodeData[key];

			if (key[0] === "@") {
				let MoonEvents = element.MoonEvents;

				if (MoonEvents === undefined) {
					MoonEvents = element.MoonEvents = {
						[key]: value
					};
				} else {
					MoonEvents[key] = value;
				}

				element.addEventListener(key.slice(1), ($event) => {
					MoonEvents[key]($event);
				});
			} else if (key !== "children" && value !== false) {
				element.setAttribute(key, value);
			}
		}

		// Recursively append children.
		const nodeDataChildren = nodeData.children;

		for (let i = 0; i < nodeDataChildren.length; i++) {
			const childOld = executeCreate(nodeDataChildren[i]);

			element.appendChild(childOld.element);
			children.push(childOld);
		}
	}

	// Return an old node with a reference to the immutable node and mutable
	// element. This is to help performance and allow static nodes to be reused.
	return {
		element,
		node,
		children
	};
}
function executeCreate ( node ) { let element ; let children = [ ] ; if ( node . type === types . text ) { // Create a text node using the text content from the default key. element = document . createTextNode ( node . data [ "" ] ) ; } else { const nodeData = node . data ; // Create a DOM element. element = document . createElement ( node . name ) ; // Set data, events, and attributes. for ( let key in nodeData ) { const value = nodeData [ key ] ; if ( key [ 0 ] === "@" ) { let MoonEvents = element . MoonEvents ; if ( MoonEvents === undefined ) { MoonEvents = element . MoonEvents = { [ key ] : value } ; } else { MoonEvents [ key ] = value ; } element . addEventListener ( key . slice ( 1 ) , ( $event ) => { MoonEvents [ key ] ( $event ) ; } ) ; } else if ( key !== "children" && value !== false ) { element . setAttribute ( key , value ) ; } } // Recursively append children. const nodeDataChildren = nodeData . children ; for ( let i = 0 ; i < nodeDataChildren . length ; i ++ ) { const childOld = executeCreate ( nodeDataChildren [ i ] ) ; element . appendChild ( childOld . element ) ; children . push ( childOld ) ; } } // Return an old node with a reference to the immutable node and mutable // element. This is to help performance and allow static nodes to be reused. return { element , node , children } ; }
Creates an old reference node from a view node.

@param {Object} node
@returns {Object} node to be used as an old node
Creates an old reference node from a view node .