mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 22:19:41 +01:00
40 lines
794 B
JavaScript
40 lines
794 B
JavaScript
import Storage from "./storage";
|
|
|
|
export default class Indexer extends Storage {
|
|
constructor(context, type) {
|
|
super(context);
|
|
this.type = type;
|
|
this.indices = [];
|
|
}
|
|
|
|
async init() {
|
|
this.indices = (await this.read(this.type, true)) || [];
|
|
}
|
|
|
|
exists(key) {
|
|
return this.indices.includes(key);
|
|
}
|
|
|
|
async index(key) {
|
|
this.indices[this.indices.length] = key;
|
|
await this.write(this.type, this.indices);
|
|
}
|
|
|
|
async getIndices() {
|
|
return this.indices;
|
|
}
|
|
|
|
async deindex(key) {
|
|
this.indices.splice(this.indices.indexOf(key), 1);
|
|
await this.write(this.type, this.indices);
|
|
}
|
|
|
|
async clear() {
|
|
for (var i = 0; i < this.indices.length; ++i) {
|
|
let key = this.indices[i];
|
|
await this.remove(key);
|
|
}
|
|
this.indices = [];
|
|
}
|
|
}
|