core: use migrations to dedup shortcuts

This commit is contained in:
Abdullah Atta
2022-10-17 22:37:23 +05:00
parent 577d50b512
commit cf8ed91102
2 changed files with 6 additions and 23 deletions

View File

@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Collection from "./collection";
import { EV, EVENTS } from "../common";
/**
* @typedef {{
@@ -45,11 +44,6 @@ export default class Shortcuts extends Collection {
await this._collection.addItem(shortcut);
}
async init() {
await super.init();
await this.dedupe();
}
/**
*
* @param {Partial<Shortcut>} shortcut
@@ -156,20 +150,4 @@ export default class Shortcuts extends Collection {
await this._collection.removeItem(id);
}
}
async dedupe() {
const oldShortcuts = this.all.filter(
(shortcut) => shortcut.id !== shortcut.item.id
);
for (const shortcut of oldShortcuts) {
await this._collection.addItem({ ...shortcut, id: shortcut.item.id });
}
for (const shortcut of oldShortcuts) {
await this._collection.removeItem(shortcut.id);
}
if (oldShortcuts.length > 0) EV.publish(EVENTS.appRefreshRequested);
}
}

View File

@@ -111,6 +111,11 @@ const migrations = [
item.type = "tiptap";
return item;
},
shortcut: (item) => {
if (item.id === item.item.id) return item;
item.id = item.item.id;
return item;
},
tiptap: (item) => {
return changeSessionContentType(item);
},