Skip to content

Instantly share code, notes, and snippets.

@g-patel
Last active February 14, 2017 20:43
Show Gist options
  • Save g-patel/a0cad51b96d554f5956b96e26928188f to your computer and use it in GitHub Desktop.
Save g-patel/a0cad51b96d554f5956b96e26928188f to your computer and use it in GitHub Desktop.
import Vue from 'vue';
Vue.config.devtools = true;
const componentsContext = require.context('./components', true, /\.vue$/);
const ComponentsById = {};
const ComponentsByName = {};
const ComponentsMap = {};
const cMap = {};
const ComponentNames = [];
require('./index.styl');
componentsContext.keys().forEach((key) => {
const component = componentsContext(key);
ComponentsById[component.data().uuid] = component;
if (!ComponentsMap[component.data().defaults.type]) {
ComponentsMap[component.data().defaults.type] = {};
}
ComponentsMap[component.data().defaults.type][component.name] = component;
cMap[component.name] = component;
ComponentNames.push(component.name);
ComponentsByName[component.name] = component;
});
const initComponents = (fragmentIdMap) => {
for (const cid in fragmentIdMap) {
const fragment = ComponentsById[fragmentIdMap[cid].uuid];
const instance = new Vue(_.extend({}, ComponentsById[fragmentIdMap[cid].uuid], {
propsData: fragmentIdMap[cid].propsData
}));
const mount = function () {
instance.$mount(`[data-col-id="${cid}"] > :only-child`);
};
if (instance.async) {
instance.$on('rendered', function () {
mount();
});
} else {
mount();
}
}
}
};
export { ComponentsMap, ComponentsById, ComponentNames, ComponentsByName, initComponents, Vue };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment