two concurrent saves could land out of order
This commit is contained in:
1 parent
d3fb5b4383
commit
3ac82877f7
1 file changed
+11
-2
@@ -97,11 +97,20 @@ module.exports = class RibbonClasp extends Plugin {
|
|||||||
this.mergeNewItems(ribbon);
|
this.mergeNewItems(ribbon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a drag saves, and the dom change it makes wakes the observer up, which can
|
||||||
|
// save again before the first one has finished writing. queue them instead.
|
||||||
|
save() {
|
||||||
|
this.writing = Promise.resolve(this.writing)
|
||||||
|
.catch(() => {})
|
||||||
|
.then(() => this.saveData(this.settings));
|
||||||
|
return this.writing;
|
||||||
|
}
|
||||||
|
|
||||||
recordOrder(ribbon) {
|
recordOrder(ribbon) {
|
||||||
const ids = ribbon.items.map((item) => item.id);
|
const ids = ribbon.items.map((item) => item.id);
|
||||||
if (this.sameOrder(ids, this.settings.order)) return;
|
if (this.sameOrder(ids, this.settings.order)) return;
|
||||||
this.settings.order = ids;
|
this.settings.order = ids;
|
||||||
this.saveData(this.settings);
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// only append icons we haven't seen before instead of overwriting the
|
// only append icons we haven't seen before instead of overwriting the
|
||||||
@@ -113,7 +122,7 @@ module.exports = class RibbonClasp extends Plugin {
|
|||||||
const newIds = ribbon.items.map((item) => item.id).filter((id) => !known.has(id));
|
const newIds = ribbon.items.map((item) => item.id).filter((id) => !known.has(id));
|
||||||
if (newIds.length === 0) return;
|
if (newIds.length === 0) return;
|
||||||
this.settings.order = [...this.settings.order, ...newIds];
|
this.settings.order = [...this.settings.order, ...newIds];
|
||||||
this.saveData(this.settings);
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
sameOrder(a, b) {
|
sameOrder(a, b) {
|
||||||
|
|||||||
Reference in new issue
Block a user