Use component this scoped function instead of Vue global function for getRidOfEdges

This commit is contained in:
Pawel Kowalski 2018-08-18 00:53:57 +02:00
parent d6d8d60c9b
commit bc29989908
3 changed files with 16 additions and 21 deletions

View File

@ -11,29 +11,26 @@ import store from '@/store/index'
Vue.config.productionTip = false Vue.config.productionTip = false
// TODO: Move into a separate project // TODO: Move into a separate project as a plugin
// //
const EdgesNodePlugin = {} function getRidOfEdges(collection) {
EdgesNodePlugin.install = function (Vue, options) { if (typeof collection === 'object') {
Vue.getRidOfEdges = function getRidOfEdges(collection) { let newObj = {}
if (typeof collection === 'object') { for (const k in collection) {
let newObj = {} if (k === 'edges' || k === 'node') {
for (const k in collection) { newObj = getRidOfEdges(collection[k])
if (k === 'edges' || k === 'node') { } else {
newObj = getRidOfEdges(collection[k]) newObj[k] = getRidOfEdges(collection[k])
} else { delete newObj[k]['__typename']
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(VueApollo)
Vue.use(VueAxios, axios) Vue.use(VueAxios, axios)

View File

@ -16,7 +16,6 @@
</template> </template>
<script> <script>
import Vue from 'vue'
import ALL_MODULES from '@/graphql/gql/allModules.gql' import ALL_MODULES from '@/graphql/gql/allModules.gql'
export default { export default {
@ -33,7 +32,7 @@
manual: true, manual: true,
result({data, loading, networkStatus}) { result({data, loading, networkStatus}) {
if (!loading) { if (!loading) {
this.modules = Vue.getRidOfEdges(data).modules this.modules = this.$getRidOfEdges(data).modules
} }
} }
} }

View File

@ -3,7 +3,6 @@
</template> </template>
<script> <script>
import Vue from 'vue'
import Module from '@/components/Module.vue'; import Module from '@/components/Module.vue';
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql'; import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
@ -18,7 +17,7 @@
manual: true, manual: true,
result({data, loading, networkStatus}) { result({data, loading, networkStatus}) {
if (!loading) { if (!loading) {
const purgedData = Vue.getRidOfEdges(data) const purgedData = this.$getRidOfEdges(data)
this.module = purgedData.modules[0] this.module = purgedData.modules[0]
} }
} }