1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

add sleep function

This commit is contained in:
lana-k
2021-08-23 22:20:03 +02:00
parent ec3ec6f57a
commit bcd98fe1ad
3 changed files with 29 additions and 24 deletions

View File

@@ -11,5 +11,11 @@ export default {
clearTimeout(timeout) clearTimeout(timeout)
timeout = setTimeout(() => func.apply(this, arguments), ms) timeout = setTimeout(() => func.apply(this, arguments), ms)
} }
},
sleep (ms) {
return new Promise(resolve => {
setTimeout(() => { resolve() }, ms)
})
} }
} }

View File

@@ -86,6 +86,7 @@ import PngIcon from '@/components/svg/png'
import ClipboardIcon from '@/components/svg/clipboard' import ClipboardIcon from '@/components/svg/clipboard'
import cIo from '@/lib/utils/clipboardIo' import cIo from '@/lib/utils/clipboardIo'
import loadingDialog from '@/components/LoadingDialog' import loadingDialog from '@/components/LoadingDialog'
import time from '@/lib/utils/time'
export default { export default {
name: 'DataView', name: 'DataView',
@@ -127,12 +128,11 @@ export default {
nextTick allows you to do something after you have changed the data and VueJS has updated the DOM based on your data change, but before the browser has rendered those changed on the page. nextTick allows you to do something after you have changed the data and VueJS has updated the DOM based on your data change, but before the browser has rendered those changed on the page.
Lees meer van Katinka Hesselink: http://www.hesselinkwebdesign.nl/2019/nexttick-vs-settimeout-in-vue/ http://www.hesselinkwebdesign.nl/2019/nexttick-vs-settimeout-in-vue/
*/ */
setTimeout(() => { await time.sleep(0)
this.$refs.viewComponent.saveAsPng() this.$refs.viewComponent.saveAsPng()
}, 0)
}, },
getOptionsForSave () { getOptionsForSave () {
return this.$refs.viewComponent.getOptionsForSave() return this.$refs.viewComponent.getOptionsForSave()
@@ -143,16 +143,15 @@ export default {
this.$modal.show('prepareCopy') this.$modal.show('prepareCopy')
const t0 = performance.now() const t0 = performance.now()
setTimeout(async () => { await time.sleep(0)
this.dataToCopy = await this.$refs.viewComponent.prepareCopy() this.dataToCopy = await this.$refs.viewComponent.prepareCopy()
const t1 = performance.now() const t1 = performance.now()
if ((t1 - t0) < 950) { if ((t1 - t0) < 950) {
this.$modal.hide('prepareCopy') this.$modal.hide('prepareCopy')
this.copyToClipboard() this.copyToClipboard()
} else { } else {
this.preparingCopy = false this.preparingCopy = false
} }
}, 0)
} else { } else {
alert("Your browser doesn't support copying images into the clipboard. If you use Firefox you can enable it by setting dom.events.asyncClipboard.clipboardItem to true.") alert("Your browser doesn't support copying images into the clipboard. If you use Firefox you can enable it by setting dom.events.asyncClipboard.clipboardItem to true.")
} }

View File

@@ -70,6 +70,7 @@ import IconButton from '@/components/IconButton'
import csv from '@/lib/csv' import csv from '@/lib/csv'
import fIo from '@/lib/utils/fileIo' import fIo from '@/lib/utils/fileIo'
import cIo from '@/lib/utils/clipboardIo' import cIo from '@/lib/utils/clipboardIo'
import time from '@/lib/utils/time'
import loadingDialog from '@/components/LoadingDialog' import loadingDialog from '@/components/LoadingDialog'
export default { export default {
@@ -125,16 +126,15 @@ export default {
this.$modal.show('prepareCSVCopy') this.$modal.show('prepareCSVCopy')
const t0 = performance.now() const t0 = performance.now()
setTimeout(async () => { await time.sleep(0)
this.dataToCopy = csv.serialize(this.result) this.dataToCopy = csv.serialize(this.result)
const t1 = performance.now() const t1 = performance.now()
if ((t1 - t0) < 950) { if ((t1 - t0) < 950) {
this.$modal.hide('prepareCSVCopy') this.$modal.hide('prepareCSVCopy')
this.copyToClipboard() this.copyToClipboard()
} else { } else {
this.preparingCopy = false this.preparingCopy = false
} }
}, 0)
} else { } else {
alert("Your browser doesn't support copying images into the clipboard. If you use Firefox you can enable it by setting dom.events.asyncClipboard.clipboardItem to true.") alert("Your browser doesn't support copying images into the clipboard. If you use Firefox you can enable it by setting dom.events.asyncClipboard.clipboardItem to true.")
} }