From 55a19bdcab6ae4c128a5816dd8aa0361a9ba9354 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 12 Apr 2022 09:42:57 +0530 Subject: [PATCH] refactor: ignore socket event emit if undefined Signed-off-by: Pranav C --- package.json | 4 ++-- packages/nc-gui/plugins/tele.js | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index aa3454b9e8..7783eef1cf 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ }, "scripts": { "build:common": "cd ./packages/nocodb-sdk; npm install; npm run build", - "start:api": "cd ./packages/nocodb; npm install; NC_DISABLE_CACHE=true NC_DISABLE_TELE=true npm run watch:run:cypress", + "start:api": "cd ./packages/nocodb; npm install; NC_DISABLE_CACHE=true NC_DISABLE_TELE=true npm run watch:run:cypress", "start:xcdb-api": "cd ./packages/nocodb; npm install; NC_DISABLE_CACHE=true NC_DISABLE_TELE=true NC_INFLECTION=camelize DATABASE_URL=sqlite:../../../scripts/cypress/fixtures/sqlite-sakila/sakila.db npm run watch:run:cypress", - "start:api:cache": "cd ./packages/nocodb; npm install; NC_DISABLE_TELE=true npm run watch:run:cypress", + "start:api:cache": "cd ./packages/nocodb; npm install; NC_DISABLE_TELE=true npm run watch:run:cypress", "start:xcdb-api:cache": "cd ./packages/nocodb; npm install; NC_DISABLE_TELE=true NC_INFLECTION=camelize DATABASE_URL=sqlite:../../../scripts/cypress/fixtures/sqlite-sakila/sakila.db npm run watch:run:cypress", "start:web": "cd ./packages/nc-gui; npm install; npm run dev", "cypress:run": "cypress run --config-file ./scripts/cypress/cypress.json", diff --git a/packages/nc-gui/plugins/tele.js b/packages/nc-gui/plugins/tele.js index 945c635751..113f52bad7 100644 --- a/packages/nc-gui/plugins/tele.js +++ b/packages/nc-gui/plugins/tele.js @@ -9,7 +9,7 @@ export default function({ }, inject) { let socket - const init = (token) => { + const init = async(token) => { if (socket) { socket.disconnect() } @@ -30,7 +30,7 @@ export default function({ app.router.onReady(() => { app.router.afterEach(function(to, from) { - if (socket || (to.path === from.path && (to.query && to.query.type) === (from.query && from.query.type))) { + if (!socket || (to.path === from.path && (to.query && to.query.type) === (from.query && from.query.type))) { return } socket.emit('page', { @@ -38,10 +38,12 @@ export default function({ path: to.matched[0].path + (to.query && to.query.type ? `?type=${to.query.type}` : '') }) }) - socket.emit('page', { - id: store.state.users.user && store.state.users.user.id, - path: route.matched[0].path + (route.query && route.query.type ? `?type=${route.query.type}` : '') - }) + if (socket) { + socket.emit('page', { + id: store.state.users.user && store.state.users.user.id, + path: route.matched[0].path + (route.query && route.query.type ? `?type=${route.query.type}` : '') + }) + } }) const tele = { @@ -61,11 +63,11 @@ export default function({ function getListener(binding) { return function(e) { + if (!socket) { return } const cat = window.location.hash.replace(/\d+\/(?=dashboard)/, '') const event = binding.value && binding.value[0] const data = binding.value && binding.value[1] const extra = binding.value && binding.value.slice(2) - tele.emit(event, { cat, @@ -87,14 +89,14 @@ export default function({ store.watch(state => state.project.projectInfo && state.project.projectInfo.teleEnabled && state.users.token, (token) => { if (token) { - init(token) + init(token).then(() => {}) } else if (socket) { socket.disconnect() socket = null } }) if (store.state.project.projectInfo && store.state.project.projectInfo.teleEnabled && store.state.users.token) { - init(store.state.users.token) + init(store.state.users.token).then(() => {}) } }