export function asArray(element) {
	if (Array.isArray(element)) {
		return element;
	}
	if (element.props && element.props.children) {
		return asArray(element.props.children);
	} else {
		return [element];
	}
}


export function forEachChildElement(dataModel, callback) {
	if (Array.isArray(dataModel.props.children)) {
		for (const child of dataModel.props.children) {
			if (child) {
				const stop = callback(child);
				if (stop === true) {
					return true;
				}
			}
		}
		return false;
	} else {
		return dataModel.props.children ? callback(dataModel.props.children) : false;
	}
}


export function forEachChildElementRecursive(dataModel, callback) {
	return forEachChildElement(dataModel, child => {
		if (!child) {
			return false;
		}
		const stop = callback(child);
		if (stop === true) {
			return true;
		}
		return forEachChildElementRecursive(child, callback);
	});
}


export function findChildElement(dataModel, name) {
	let result = null;
	forEachChildElement(dataModel, element => {
		if (!element) {
			return false;
		}
		const found = element.props.name === name;
		result = element;
		return found;
	});
	return result;
}


export function childNames(dataModel) {
	const result = [];
	forEachChildElement(dataModel, element => {
		if (!element) {
			return;
		}
		const { props, type } = element;
		if (props === undefined) {
			return;
		}
		if (props.hasOwnProperty("children")) {
			result.push(...childNames(element));
		} else if (type.dataModelType && props.name) {
			result.push(props.name);
		}
	});
	return result;
}


export function getPropsAndValues(dataModel, data, callback) {
	const table = [];
	forEachChildElement(dataModel, element => {
		if (!element) {
			return;
		}
		const { props, type } = element;
		if (props === undefined) {
			return;
		}
		if (props.hasOwnProperty("children")) {
			getPropsAndValues(element, data, callback);
		} else if (type.dataModelType && props.name) {
			let value;
			if (data.hasOwnProperty(props.name)) {
				value = data[props.name];
			} else {
				value = type.dynamicDefaultValue ? type.dynamicDefaultValue(props) : props.defaultValue;
			}
			callback({...props, value});
		}
	});
	return table;
}


export function assignData(dataModel, source, destination = {}) {
	forEachChildElement(dataModel, element => {
		if (!element) {
			return;
		}
		const { props, type } = element;
		if (props === undefined) {
			return;
		}
		if (props.hasOwnProperty("children")) {
			assignData(element, source, destination);
		} else if (type.dataModelType) {
			if (source.hasOwnProperty(props.name)) {
				destination[props.name] = source[props.name];
			} else {
				destination[props.name] = type.dynamicDefaultValue ? type.dynamicDefaultValue(props) : props.defaultValue;
			}
		}
	});
	return destination;
}


export function defaultData(dataModel) {
	return assignData(dataModel, {});
}


export function shallowEqual(objA, objB) {
	if (objA === objB) {
		return true;
	}
	var key;
	// Test for A's keys different from B.
	for (key in objA) {
		if (objA.hasOwnProperty(key) && (!objB.hasOwnProperty(key) || objA[key] !== objB[key])) {
			return false;
		}
	}
	// Test for B's keys missing from A.
	for (key in objB) {
		if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {
			return false;
		}
	}
	return true;
}

@@ -1375,32 +1375,16 @@
 ops.
-hasOwnProperty(%22
 children
 %22)) 
@@ -1375,26 +1375,24 @@
 ops.children
-%22)
 ) %7B%0A%09%09%09resul
@@ -1784,32 +1784,16 @@
 ops.
-hasOwnProperty(%22
 children
 %22)) 
@@ -1784,26 +1784,24 @@
 ops.children
-%22)
 ) %7B%0A%09%09%09getPr
@@ -2383,32 +2383,16 @@
 ops.
-hasOwnProperty(%22
 children
 %22)) 
@@ -2391,10 +2391,8 @@
 dren
-%22)
 ) %7B%0A

fix assignData