lib/boilerplate.view.js
function buildFunction( def, code, varName ) {
    if ( isSpecial( def, "behind" ) ) {
        const behindFunctionName = def[ 1 ];
        code.addNeededBehindFunction( behindFunctionName );
        code.that = true;
        return [
            "value => {",
            "  try {",
            `    CODE_BEHIND${keySyntax(behindFunctionName)}.call(that, value, ${varName});`,
            "  }",
            "  catch( ex ) {",
            "    console.error(`Exception in code behind \"" +
            behindFunctionName + "\" of module \"" +
            code.moduleName + "\": ${ex}`);",
            "  }",
            "}"
        ];
    }

    if ( isSpecial( def, "toggle" ) ) {
        const nameOfTheBooleanToToggle = def[ 1 ];
        const namesOfTheBooleanToToggle = Array.isArray( nameOfTheBooleanToToggle ) ?
            nameOfTheBooleanToToggle : [ nameOfTheBooleanToToggle ];
        const body = namesOfTheBooleanToToggle
            .map( name => `${getElemVarFromPath(name)} = !${getElemVarFromPath(name)};` );
        return [
            "() => {",
            body,
            "}"
        ];
    }

    throw Error( `Function definition expected, but found ${JSON.stringify(def)}!` );
}
function buildFunction( def, code, varName ) {
    if ( isSpecial( def, "behind" ) ) {
        const behindFunctionName = def[ 1 ];
        code.addNeededBehindFunction( behindFunctionName );
        code.that = true;
        return [
            "value => {",
            "  try {",
            `    CODE_BEHIND${keySyntax(behindFunctionName)}.call(that, value, ${varName});`,
            "  }",
            "  catch( ex ) {",
            "    console.error(`Exception in code behind \"" +
            behindFunctionName + "\" of module \"" +
            code.moduleName + "\": ${ex}`);",
            "  }",
            "}"
        ];
    }

    if ( isSpecial( def, "toggle" ) ) {
        const nameOfTheBooleanToToggle = def[ 1 ];
        const namesOfTheBooleanToToggle = Array.isArray( nameOfTheBooleanToToggle ) ?
            nameOfTheBooleanToToggle : [ nameOfTheBooleanToToggle ];
        const body = namesOfTheBooleanToToggle
            .map( name => `${getElemVarFromPath(name)} = !${getElemVarFromPath(name)};` );
        return [
            "() => {",
            body,
            "}"
        ];
    }

    throw Error( `Function definition expected, but found ${JSON.stringify(def)}!` );
}
function buildFunction ( def , code , varName ) { if ( isSpecial ( def , "behind" ) ) { const behindFunctionName = def [ 1 ] ; code . addNeededBehindFunction ( behindFunctionName ) ; code . that = true ; return [ "value => {" , "  try {" , ` ${ keySyntax ( behindFunctionName ) } ${ varName } ` , "  }" , "  catch( ex ) {" , "    console.error(`Exception in code behind \"" + behindFunctionName + "\" of module \"" + code . moduleName + "\": ${ex}`);" , "  }" , "}" ] ; } if ( isSpecial ( def , "toggle" ) ) { const nameOfTheBooleanToToggle = def [ 1 ] ; const namesOfTheBooleanToToggle = Array . isArray ( nameOfTheBooleanToToggle ) ? nameOfTheBooleanToToggle : [ nameOfTheBooleanToToggle ] ; const body = namesOfTheBooleanToToggle . map ( name => ` ${ getElemVarFromPath ( name ) } ${ getElemVarFromPath ( name ) } ` ) ; return [ "() => {" , body , "}" ] ; } throw Error ( ` ${ JSON . stringify ( def ) } ` ) ; }
Create the code for a function.

@example
{Behind onVarChanged}
{Toggle show-menu}

@param  {object} def - Function definition.
@param  {object} code - Needed for `code.section.ons`.
@param {string} varName - Name of the object owning the attribute we want to listen on.

@return {array} Resulting code as an array.
Create the code for a function .