From dc0465b0afac8ced3f80d35e58d9f812e406bfb3 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Tue, 26 Jan 2021 21:57:27 +0530 Subject: [PATCH] Refactor global instances of $api and $utils to be mixins. ... instead of Vue.prototype variables which is the idiomatic approach. Also, the refactor enables utils to be instantiated as a class that takes the i18n object for util functions to have accesss to i18n translation. --- frontend/src/main.js | 50 ++++++++++++++++++++++++------------------- frontend/src/utils.js | 38 ++++++++++++++++---------------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/frontend/src/main.js b/frontend/src/main.js index 2f3073639..c6288862f 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -7,37 +7,43 @@ import App from './App.vue'; import router from './router'; import store from './store'; import * as api from './api'; -import utils from './utils'; import { models } from './constants'; +import Utils from './utils'; // Internationalisation. Vue.use(VueI18n); - -// Create VueI18n instance with options const i18n = new VueI18n(); Vue.use(Buefy, {}); Vue.config.productionTip = false; -// Custom global elements. -Vue.prototype.$api = api; -Vue.prototype.$utils = utils; - -Vue.prototype.$reloadServerConfig = () => { - // Get the config.js