Refactor another plugin

This commit is contained in:
Ramon Wenger 2020-03-25 13:15:18 +01:00
parent 6082d37177
commit e177608360
2 changed files with 30 additions and 24 deletions

View File

@ -18,34 +18,12 @@ import autoGrow from '@/directives/auto-grow'
import clickOutside from '@/directives/click-outside'
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import VueModal from '@/plugins/modal';
import VueRemoveEdges from '@/plugins/edges';
Vue.config.productionTip = false;
Vue.use(VueModal);
// TODO: Move into a separate project as a plugin
//
function getRidOfEdges(collection) {
if (typeof collection === 'object' && collection && !Array.isArray(collection)) {
let newObj = {};
for (const k in collection) {
if (k === 'edges') {
return collection.edges.map(edge => getRidOfEdges(edge.node));
} else {
newObj[k] = getRidOfEdges(collection[k]);
if (newObj[k]) {
// delete newObj[k]['__typename']
}
}
}
return newObj
} else {
return collection
}
}
Object.defineProperty(Vue.prototype, '$getRidOfEdges', {value: getRidOfEdges});
Vue.use(VueRemoveEdges);
Vue.use(VueApollo);
Vue.use(VueAxios, axios);
Vue.use(VueVimeoPlayer);

View File

@ -0,0 +1,28 @@
const getRidOfEdges = (collection) => {
if (typeof collection === 'object' && collection && !Array.isArray(collection)) {
let newObj = {};
for (const k in collection) {
if (collection.hasOwnProperty(k)) {
if (k === 'edges') {
return collection.edges.map(edge => getRidOfEdges(edge.node));
} else {
newObj[k] = getRidOfEdges(collection[k]);
if (newObj[k]) {
// delete newObj[k]['__typename']
}
}
}
}
return newObj
} else {
return collection
}
};
const EdgesPlugin = {
install(Vue, options) {
Vue.prototype.$getRidOfEdges = getRidOfEdges;
}
};
export default EdgesPlugin;