lib/model/compiler.js
function compileCoercion( attributes ) {
	if ( !attributes || typeof attributes !== "object" || Array.isArray( attributes ) ) {
		throw new TypeError( "definition of attributes must be object" );
	}

	const attributeNames = Object.keys( attributes );
	const numAttributes = attributeNames.length;
	const coercion = [];

	for ( let ai = 0; ai < numAttributes; ai++ ) {
		const attributeName = attributeNames[ai];
		const attribute = attributes[attributeName];

		const handler = Types.selectByName( attribute.type );

		const { args, body } = extractBody( handler.coerce );
		if ( args.length < 2 ) {
			throw new TypeError( `coerce() of ModelType for handling ${attribute.type} values must accept two arguments` );
		}

		coercion[ai] = `
{
	let ${args[0]} = __props["${attributeName}"];
	const ${args[1]} = __attrs["${attributeName}"];

	{
		${body.replace( ptnTrailingReturn, ( all, term ) => `__props["${attributeName}"] = ${term.trim()};` )}
	}
}
		`;
	}

	// eslint-disable-next-line no-new-func
	return new Function( `
const __attrs = this.constructor.schema.attributes;
const __props = this.properties;

${coercion.join( "" )}
` );
}
function compileCoercion( attributes ) {
	if ( !attributes || typeof attributes !== "object" || Array.isArray( attributes ) ) {
		throw new TypeError( "definition of attributes must be object" );
	}

	const attributeNames = Object.keys( attributes );
	const numAttributes = attributeNames.length;
	const coercion = [];

	for ( let ai = 0; ai < numAttributes; ai++ ) {
		const attributeName = attributeNames[ai];
		const attribute = attributes[attributeName];

		const handler = Types.selectByName( attribute.type );

		const { args, body } = extractBody( handler.coerce );
		if ( args.length < 2 ) {
			throw new TypeError( `coerce() of ModelType for handling ${attribute.type} values must accept two arguments` );
		}

		coercion[ai] = `
{
	let ${args[0]} = __props["${attributeName}"];
	const ${args[1]} = __attrs["${attributeName}"];

	{
		${body.replace( ptnTrailingReturn, ( all, term ) => `__props["${attributeName}"] = ${term.trim()};` )}
	}
}
		`;
	}

	// eslint-disable-next-line no-new-func
	return new Function( `
const __attrs = this.constructor.schema.attributes;
const __props = this.properties;

${coercion.join( "" )}
` );
}
function compileCoercion ( attributes ) { if ( ! attributes || typeof attributes !== "object" || Array . isArray ( attributes ) ) { throw new TypeError ( "definition of attributes must be object" ) ; } const attributeNames = Object . keys ( attributes ) ; const numAttributes = attributeNames . length ; const coercion = [ ] ; for ( let ai = 0 ; ai < numAttributes ; ai ++ ) { const attributeName = attributeNames [ ai ] ; const attribute = attributes [ attributeName ] ; const handler = Types . selectByName ( attribute . type ) ; const { args , body } = extractBody ( handler . coerce ) ; if ( args . length < 2 ) { throw new TypeError ( ` ${ attribute . type } ` ) ; } coercion [ ai ] = ` ${ args [ 0 ] } ${ attributeName } ${ args [ 1 ] } ${ attributeName } ${ body . replace ( ptnTrailingReturn , ( all , term ) => ` ${ attributeName } ${ term . trim ( ) } ` ) } ` ; } // eslint-disable-next-line no-new-func return new Function ( ` ${ coercion . join ( "" ) } ` ) ; }
Creates function coercing all attributes.

@param {object<string,object>} attributes definition of essential attributes
@returns {function()} concatenated implementation of all defined attributes' coercion handlers
Creates function coercing all attributes .