Buffer file writes, because writing to file after every keypress has bad consequences (#4242)
* Buffer file writes, because writing to file after every keypress does bad things * fix: kevin -- added timeouts for the time being since the workflow for saving data to disk is now changed --------- Co-authored-by: Kevin Nadro <kevin@zoo.dev>
This commit is contained in:
@ -18,6 +18,7 @@ export default class CodeManager {
|
||||
#updateState: (arg: string) => void = () => {}
|
||||
private _currentFilePath: string | null = null
|
||||
private _hotkeys: { [key: string]: () => void } = {}
|
||||
private timeoutWriter: ReturnType<typeof setTimeout> | undefined = undefined
|
||||
|
||||
constructor() {
|
||||
if (isDesktop()) {
|
||||
@ -115,7 +116,11 @@ export default class CodeManager {
|
||||
|
||||
async writeToFile() {
|
||||
if (isDesktop()) {
|
||||
setTimeout(() => {
|
||||
// Only write our buffer contents to file once per second. Any faster
|
||||
// and file-system watchers which read, will receive empty data during
|
||||
// writes.
|
||||
clearTimeout(this.timeoutWriter)
|
||||
this.timeoutWriter = setTimeout(() => {
|
||||
// Wait one event loop to give a chance for params to be set
|
||||
// Save the file to disk
|
||||
this._currentFilePath &&
|
||||
@ -126,7 +131,7 @@ export default class CodeManager {
|
||||
console.error('error saving file', err)
|
||||
toast.error('Error saving file, please check file permissions')
|
||||
})
|
||||
})
|
||||
}, 1000)
|
||||
} else {
|
||||
safeLSSetItem(PERSIST_CODE_KEY, this.code)
|
||||
}
|
||||
|
Reference in New Issue
Block a user