-
-
Save Comandeer/86b3c882756e2e303fb4e40520474325 to your computer and use it in GitHub Desktop.
getListeners helper function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSettings( { template, style, script } ) { | |
[…] | |
function getListeners( settings ) { // 1 | |
const listeners = {}; | |
Object.entries( settings ).forEach( ( [ setting, value ] ) => { // 3 | |
if ( setting.startsWith( 'on' ) ) { // 4 | |
listeners[ setting[ 2 ].toLowerCase() + setting.substr( 3 ) ] = value; // 5 | |
} | |
} ); | |
return listeners; | |
} | |
return import( jsURL ).then( ( module ) => { | |
const listeners = getListeners( module.default ); // 2 | |
return { | |
name: module.default.name, | |
listeners, // 6 | |
template, | |
style | |
} | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment