Save to storage at most every 5 seconds

pull/1/head
Alex Beregszaszi 8 years ago
parent 98fb006d0b
commit 0d532f0090
  1. 21
      src/app.js

@ -452,20 +452,31 @@ var run = function () {
var previousInput = '' var previousInput = ''
var compileTimeout = null var compileTimeout = null
var saveTimeout = null
function editorOnChange () { function editorOnChange () {
var input = editor.getValue() var input = editor.getValue()
// save contents
editor.setCacheFileContent(input)
if (input === '') { // if there's no change, don't do anything
if (input === previousInput) {
return return
} }
previousInput = input
if (input === previousInput) { // fire storage update
// NOTE: save at most once per 5 seconds
if (saveTimeout) {
window.clearTimeout(saveTimeout)
}
saveTimeout = window.setTimeout(function () {
var input = editor.getValue()
editor.setCacheFileContent(input)
}, 5000)
// special case: there's nothing else to do
if (input === '') {
return return
} }
previousInput = input
if (!autoCompile) { if (!autoCompile) {
return return

Loading…
Cancel
Save