Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Aug 14, 2024
1 parent e95116e commit d0e1a71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/src/dictionary/dictionary-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class DictionaryDb {
private ready = false;

// eslint-disable-next-line
public collection: Collection<any>;
public collection: Collection<any> | undefined;

constructor(options: {
url: string;
Expand Down Expand Up @@ -82,6 +82,9 @@ export class DictionaryDb {

private async addDictionaryToLoki(dictionary: T.Dictionary): Promise<"done"> {
return await new Promise((resolve: (value: "done") => void, reject) => {
if (!this.collection) {
reject("dictionary not initialized");
}
// Add it to Lokijs
this.collection = this.lokidb.addCollection(
this.dictionaryCollectionName,
Expand Down Expand Up @@ -201,8 +204,10 @@ export class DictionaryDb {
notifyUpdateComing();
this.ready = false;
localStorage.removeItem(this.dictionaryInfoLocalStorageKey);
this.collection.clear();
this.lokidb.removeCollection(this.dictionaryCollectionName);
if (this.collection) {
this.collection.clear();
this.lokidb.removeCollection(this.dictionaryCollectionName);
}
await (async () => {
return new Promise((resolve: (value: "done") => void) => {
this.lokidb.saveDatabase(() => {
Expand All @@ -225,7 +230,7 @@ export class DictionaryDb {
*/
// TODO: not working in app usage now now with new 'this' issues
public findOneByTs(ts: number): T.DictionaryEntry | undefined {
if (!this.ready) {
if (!this.ready || !this.collection) {
return undefined;
}
const res = this.collection.by("ts", ts);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/src/dictionary/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const dictDb = new DictionaryDb({
});

function queryP(p: string): T.DictionaryEntry[] {
if (!dictDb.collection) {
return [];
}
return dictDb.collection.find({ p });
}
const memoizedQueryP = queryP;
Expand Down

0 comments on commit d0e1a71

Please sign in to comment.