1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-10 03:58:54 +08:00

events refactor

This commit is contained in:
lana-k
2022-06-25 22:37:09 +02:00
parent 48e311bff8
commit d56604a7d6
14 changed files with 66 additions and 100 deletions

View File

@@ -79,13 +79,9 @@ class Database {
this.dbName = file ? fu.getFileName(file) : 'database'
this.refreshSchema()
send({
category: 'database',
action: 'import',
value: file ? file.size : 0,
label: file
? 'from=sqlite new_db=true'
: 'from=none new_db=true'
send('database.import', file ? file.size : 0, {
from: file ? 'sqlite' : 'none',
new_db: true
})
}
@@ -125,12 +121,7 @@ class Database {
throw new Error(data.error)
}
fu.exportToFile(data, fileName)
send({
category: 'database',
action: 'export',
value: data.byteLength,
label: 'to=sqlite'
})
send('database.export', data.byteLength, { to: 'sqlite' })
}
async validateTableName (name) {

View File

@@ -106,11 +106,7 @@ export default {
.then(str => {
const inquires = this.deserialiseInquiries(str)
send({
category: 'inquiry',
action: 'import',
value: inquires.length
})
send('inquiry.import', inquires.length)
return inquires
})
@@ -119,11 +115,7 @@ export default {
const jsonStr = this.serialiseInquiries(inquiryList)
fu.exportToFile(jsonStr, fileName)
send({
category: 'inquiry',
action: 'export',
value: inquiryList.length
})
send('inquiry.export', inquiryList.length)
},
async readPredefinedInquiries () {

View File

@@ -1,8 +1,12 @@
export function send (payload) {
console.log(payload)
export function send (name, value, labels) {
console.log(name, value, labels)
const event = new CustomEvent('sqliteviz-app-event', {
detail: payload
detail: {
name,
value,
labels
}
})
window.dispatchEvent(event)
}