mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-12 22:50:54 +03:00
Use window.requestIdleCallback
in StateStore.prototype.save
This should alleviate some of the pressure of serializing changes on the main thread. We're assuming that `deadline.timeRemaining()` is high enough to compute the serialization because there's no simple path to serialize state across many `requestIdleCallback`s (e.g. because state might change between two callbacks).
This commit is contained in:
parent
e39d200a77
commit
677568d9af
@ -24,16 +24,18 @@ class StateStore {
|
||||
}
|
||||
|
||||
save (key, value) {
|
||||
return this.dbPromise.then(db => {
|
||||
if (!db) return
|
||||
return new Promise((resolve, reject) => {
|
||||
window.requestIdleCallback(deadline => {
|
||||
this.dbPromise.then(db => {
|
||||
if (db == null) resolve()
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
var request = db.transaction(['states'], 'readwrite')
|
||||
.objectStore('states')
|
||||
.put({value: value, storedAt: new Date().toString()}, key)
|
||||
var request = db.transaction(['states'], 'readwrite')
|
||||
.objectStore('states')
|
||||
.put({value: value, storedAt: new Date().toString()}, key)
|
||||
|
||||
request.onsuccess = resolve
|
||||
request.onerror = reject
|
||||
request.onsuccess = resolve
|
||||
request.onerror = reject
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user