Created
January 14, 2022 16:01
-
-
Save interactiveRob/8ff0068c2c1d04c6190708c2aa18544e to your computer and use it in GitHub Desktop.
Example ES6 Functional component
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
import { exists } from '@/helpers/utilities'; | |
export let mixin = ({ node = null, config = {} } = {}) => { | |
if (!node) return false; | |
let state = { | |
node, | |
config, | |
}; | |
let module = { | |
setEventBindings() { | |
state.node.addEventListener('mouseenter', this.onMenuItemClick.bind(this)); | |
}, | |
init() { | |
if (!exists(state.node)) return; | |
this.setEventBindings(); | |
}, | |
}; | |
return module.init(); | |
}; | |
export default { | |
init({ selector, config = {} }) { | |
let selected = document.querySelectorAll(selector); | |
if (!selected.length) return; | |
return [...selected].map((node, index) => { | |
return mixin({ node, config }); | |
}); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment