Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Created January 14, 2022 16:01
Show Gist options
  • Save interactiveRob/8ff0068c2c1d04c6190708c2aa18544e to your computer and use it in GitHub Desktop.
Save interactiveRob/8ff0068c2c1d04c6190708c2aa18544e to your computer and use it in GitHub Desktop.
Example ES6 Functional component
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