From bc299899083629da558093608ab2e6dd3de12049 Mon Sep 17 00:00:00 2001 From: Pawel Kowalski Date: Sat, 18 Aug 2018 00:53:57 +0200 Subject: [PATCH] Use component this scoped function instead of Vue global function for getRidOfEdges --- client/src/main.js | 31 ++++++++++++++----------------- client/src/pages/index.vue | 3 +-- client/src/pages/module.vue | 3 +-- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/client/src/main.js b/client/src/main.js index a03b83f8..3dc8a20f 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -11,29 +11,26 @@ import store from '@/store/index' Vue.config.productionTip = false -// TODO: Move into a separate project +// TODO: Move into a separate project as a plugin // -const EdgesNodePlugin = {} -EdgesNodePlugin.install = function (Vue, options) { - Vue.getRidOfEdges = function getRidOfEdges(collection) { - if (typeof collection === 'object') { - let newObj = {} - for (const k in collection) { - if (k === 'edges' || k === 'node') { - newObj = getRidOfEdges(collection[k]) - } else { - newObj[k] = getRidOfEdges(collection[k]) - delete newObj[k]['__typename'] - } +function getRidOfEdges(collection) { + if (typeof collection === 'object') { + let newObj = {} + for (const k in collection) { + if (k === 'edges' || k === 'node') { + newObj = getRidOfEdges(collection[k]) + } else { + newObj[k] = getRidOfEdges(collection[k]) + delete newObj[k]['__typename'] } - return newObj - } else { - return collection } + return newObj + } else { + return collection } } -Vue.use(EdgesNodePlugin) +Object.defineProperty(Vue.prototype, '$getRidOfEdges', {value: getRidOfEdges}) Vue.use(VueApollo) Vue.use(VueAxios, axios) diff --git a/client/src/pages/index.vue b/client/src/pages/index.vue index 1d727c65..58b39a1e 100644 --- a/client/src/pages/index.vue +++ b/client/src/pages/index.vue @@ -16,7 +16,6 @@