Browse Source

refactor: ignore socket event emit if undefined

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1668/head
Pranav C 3 years ago
parent
commit
55a19bdcab
  1. 4
      package.json
  2. 20
      packages/nc-gui/plugins/tele.js

4
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",

20
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(() => {})
}
}

Loading…
Cancel
Save