Refactor another plugin
This commit is contained in:
parent
6082d37177
commit
e177608360
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
Loading…
Reference in New Issue