1
0
mirror of https://github.com/BoostIo/Boostnote synced 2026-02-07 13:01:40 +00:00

clean old codes

This commit is contained in:
Dick Choi
2016-07-14 14:37:26 +09:00
parent 2d46d12628
commit 922ae7a274
5 changed files with 10 additions and 101 deletions

View File

@@ -1,57 +0,0 @@
import Storage from 'browser/lib/Storage'
import _ from 'lodash'
let tasks = []
function _save (task, storageKey, note) {
note = Object.assign({}, note)
delete note._storage
task.status = 'process'
Storage
.find(storageKey)
.then((storage) => {
return storage.updateNote(note.key, note)
})
.then((note) => {
tasks.splice(tasks.indexOf(task), 1)
console.info('Note saved', note)
})
.catch((err) => {
tasks.splice(tasks.indexOf(task), 1)
console.error('Failed to save note', note)
console.error(err)
})
}
const queueSaving = function (storageKey, note) {
let key = `${storageKey}-${note.key}`
let taskIndex = _.findIndex(tasks, {
type: 'SAVE_NOTE',
key: key,
status: 'idle'
})
let task = tasks[taskIndex]
if (taskIndex < 0) {
task = {
type: 'SAVE_NOTE',
key: key,
status: 'idle',
timer: null
}
} else {
tasks.splice(taskIndex, 1)
window.clearTimeout(task.timer)
}
task.timer = window.setTimeout(() => {
_save(task, storageKey, note)
}, 1500)
tasks.push(task)
}
export default {
save: queueSaving
}