Skip to content

Instantly share code, notes, and snippets.

@hagata
Last active March 24, 2017 23:22
Show Gist options
  • Select an option

  • Save hagata/8c8b1a6cfea83a815436be8ff69baa36 to your computer and use it in GitHub Desktop.

Select an option

Save hagata/8c8b1a6cfea83a815436be8ff69baa36 to your computer and use it in GitHub Desktop.
Basic Module/Component loader. Starts up new instances of classes based on data attributes on elements in the DOM.
import {exampleModue} from '../modules/exampleModue';
const modules = {
exampleModue: exampleModue
};
function loadModules() {
const moduleNodes = document.querySelectorAll('[data-component]');
console.log('Loading', modules);
for (const node of moduleNodes) {
const moduleName = node.dataset.component;
appModules[moduleName] = new modules[moduleName](node);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment