diff --git a/client/src/main.js b/client/src/main.js index c157c29c..fba663e7 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -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); diff --git a/client/src/plugins/edges.js b/client/src/plugins/edges.js new file mode 100644 index 00000000..ea740cbb --- /dev/null +++ b/client/src/plugins/edges.js @@ -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;