mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-27 17:39:49 -04:00
fix deprecated methods in storage
fix deprecated topromise, use lastValueFrom instead.
This commit is contained in:
parent
78accd1293
commit
c181fb4504
@ -37,6 +37,7 @@ import {
|
||||
StrongsResult,
|
||||
} from '../models/strongs-state';
|
||||
import { WordToStem, IndexResult, WordLookupResult } from '../models/words-state';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
const initialState: AppState = {
|
||||
user: null,
|
||||
@ -820,7 +821,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
async getAutoComplete(keyword: string) {
|
||||
if (!this.autocomplete) {
|
||||
// if you have't populated the word list yet, do so...
|
||||
const data = await this.http.get<WordToStem[]>(`${this.dataPath}/index/word_to_stem_idx.json`).toPromise();
|
||||
const data = await lastValueFrom(this.http.get<WordToStem[]>(`${this.dataPath}/index/word_to_stem_idx.json`));
|
||||
this.autocomplete = data.map((o) => o.w);
|
||||
}
|
||||
|
||||
@ -900,8 +901,8 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
}
|
||||
|
||||
async updateCards(queries: IStorable<readonly DataReference[]>) {
|
||||
const cards: CardItem[] = [];
|
||||
const values = queries.value ?? [];
|
||||
const cards: CardItem[] = [];
|
||||
for (const q of values) {
|
||||
const card = await this.getCardByQuery(q.qry.trim(), q.type);
|
||||
cards.push(card);
|
||||
@ -1147,7 +1148,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
|
||||
let url = `${dict}${Math.ceil(sn / 100)}.json`;
|
||||
try {
|
||||
const d = await this.http.get<StrongsDefinition[]>(`${this.dataPath}/strongs/${url}`).toPromise();
|
||||
const d = await lastValueFrom(this.http.get<StrongsDefinition[]>(`${this.dataPath}/strongs/${url}`));
|
||||
result.def = d.find((el) => el.i === result.prefix + result.sn);
|
||||
} catch (err) {
|
||||
this.dispatchError(`Unable to retrieve Strong's Data for ${result.prefix}${result.sn}`);
|
||||
@ -1155,7 +1156,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
}
|
||||
|
||||
try {
|
||||
const d = await this.http.get<StrongsCrossReference[]>(`${this.dataPath}/strongscr/cr${url}`).toPromise();
|
||||
const d = await lastValueFrom(this.http.get<StrongsCrossReference[]>(`${this.dataPath}/strongscr/cr${url}`));
|
||||
|
||||
result.crossrefs = d.find((o) => o.id.toUpperCase() === result.prefix + result.sn);
|
||||
} catch (err) {
|
||||
@ -1170,7 +1171,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
// rmac is a two get process.
|
||||
// first, get the rmac code.
|
||||
try {
|
||||
const rmacCrossReferences = await this.http.get<RMACCrossReference[]>(url).toPromise();
|
||||
const rmacCrossReferences = await lastValueFrom(this.http.get<RMACCrossReference[]>(url));
|
||||
|
||||
// deal with RMAC
|
||||
const referencesForThisStrongsNumber = rmacCrossReferences.filter((el, i) => {
|
||||
@ -1191,7 +1192,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
url = `${this.dataPath}/rmac/r-${result.rmaccode.substring(0, 1)}.json`;
|
||||
|
||||
try {
|
||||
const rmacDefinitions = await this.http.get<RMACDefinition[]>(url).toPromise();
|
||||
const rmacDefinitions = await lastValueFrom(this.http.get<RMACDefinition[]>(url));
|
||||
result.rmac = rmacDefinitions.find((o) => o.id.toLowerCase() === result.rmaccode);
|
||||
} catch (err) {
|
||||
this.dispatchError('Unable to retrieve RMAC');
|
||||
@ -1250,9 +1251,9 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
|
||||
for (let i = Number(section.start.chapter); i <= Number(section.end.chapter); i++) {
|
||||
try {
|
||||
const d = await this.http
|
||||
.get<BiblePassage>(`${this.dataPath}/bibles/kjv_strongs/${section.book.bookNumber}-${i}.json`)
|
||||
.toPromise();
|
||||
const d = await lastValueFrom(
|
||||
this.http.get<BiblePassage>(`${this.dataPath}/bibles/kjv_strongs/${section.book.bookNumber}-${i}.json`)
|
||||
);
|
||||
chapters.push(d);
|
||||
} catch (err) {
|
||||
this.dispatchError(`Unable to retrieve bible passage ${BibleReference.toString(section)}.`);
|
||||
@ -1327,7 +1328,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
private async convertToParagraphPassages(chapters: BiblePassage[], section: Section) {
|
||||
// get the paragraphs the first time if you haven't already.
|
||||
if (!this.paragraphs) {
|
||||
this.paragraphs = await this.http.get<HashTable<Paragraph>>(`${this.dataPath}/bibles/paras.json`).toPromise();
|
||||
this.paragraphs = await lastValueFrom(this.http.get<HashTable<Paragraph>>(`${this.dataPath}/bibles/paras.json`));
|
||||
}
|
||||
|
||||
const passages: BibleParagraphPassage[] = [];
|
||||
@ -1514,7 +1515,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
private async getStemWordIndex() {
|
||||
this.wordToStem = new Map<string, string>();
|
||||
try {
|
||||
const r = await this.http.get<WordToStem[]>(`${this.dataPath}/index/word_to_stem_idx.json`).toPromise();
|
||||
const r = await lastValueFrom(this.http.get<WordToStem[]>(`${this.dataPath}/index/word_to_stem_idx.json`));
|
||||
|
||||
// find the right word
|
||||
for (const i of r) {
|
||||
@ -1541,7 +1542,7 @@ export class AppService extends createStateService(appReducer, initialState) {
|
||||
let r: IndexResult[];
|
||||
|
||||
try {
|
||||
r = await this.http.get<IndexResult[]>(url).toPromise();
|
||||
r = await lastValueFrom(this.http.get<IndexResult[]>(url));
|
||||
} catch (err) {
|
||||
this.dispatch(
|
||||
updateErrorAction({
|
||||
|
@ -14,6 +14,7 @@ import { isNullOrUndefined } from '../common/helpers';
|
||||
import { DataReference } from '../models/card-state';
|
||||
import { createSelector } from 'reselect';
|
||||
import { AppService } from './app.service';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
/**
|
||||
* This class handles all the storage needs of the application. It handles both
|
||||
@ -186,9 +187,9 @@ export class StorageService extends SubscriberBase {
|
||||
}
|
||||
|
||||
private async getFromLocal<T>(path: string, action: (storable: IStorable<T>) => void) {
|
||||
const hasStorable = await this.local.has(path).toPromise();
|
||||
const hasStorable = await lastValueFrom(this.local.has(path));
|
||||
if (hasStorable) {
|
||||
const localData = (await this.local.get(path).toPromise()) as IStorable<T>;
|
||||
const localData = (await lastValueFrom(this.local.get(path))) as IStorable<T>;
|
||||
// console.log('Data recieved from local store', localData);
|
||||
action(localData);
|
||||
}
|
||||
@ -232,14 +233,14 @@ export class StorageService extends SubscriberBase {
|
||||
|
||||
// console.log('Data saved to local store', data);
|
||||
// update local
|
||||
this.local.set(this.savedPagesPath, data).subscribe(
|
||||
() => {
|
||||
// nop
|
||||
},
|
||||
// error
|
||||
() => {
|
||||
this.appService.dispatchError(`Something went wrong and the Page wasn't saved. :(`);
|
||||
}
|
||||
this.addSubscription(
|
||||
this.local.set(this.savedPagesPath, data).subscribe({
|
||||
next: () => {},
|
||||
complete: () => {},
|
||||
error: () => {
|
||||
this.appService.dispatchError(`Something went wrong and the Page wasn't saved. :(`);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// update remote
|
||||
@ -258,14 +259,14 @@ export class StorageService extends SubscriberBase {
|
||||
|
||||
// console.log('Data saved to local store', data);
|
||||
// update local
|
||||
this.local.set(this.noteItemsPath, data).subscribe(
|
||||
() => {
|
||||
// nop
|
||||
},
|
||||
// error
|
||||
() => {
|
||||
this.appService.dispatchError(`Something went wrong and the Note wasn't saved. :(`);
|
||||
}
|
||||
this.addSubscription(
|
||||
this.local.set(this.noteItemsPath, data).subscribe({
|
||||
next: () => {},
|
||||
complete: () => {},
|
||||
error: () => {
|
||||
this.appService.dispatchError(`Something went wrong and the Note wasn't saved. :(`);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// update remote
|
||||
@ -289,15 +290,15 @@ export class StorageService extends SubscriberBase {
|
||||
}
|
||||
|
||||
// update local
|
||||
this.local.set(this.cardsPath, v.currentCards).subscribe({
|
||||
next: () => {
|
||||
// nop
|
||||
},
|
||||
// error
|
||||
error: () => {
|
||||
this.appService.dispatchError(`Something went wrong and the current cards weren't saved. :(`);
|
||||
},
|
||||
});
|
||||
this.addSubscription(
|
||||
this.local.set(this.cardsPath, v.currentCards).subscribe({
|
||||
next: () => {},
|
||||
complete: () => {},
|
||||
error: () => {
|
||||
this.appService.dispatchError(`Something went wrong and the current cards weren't saved. :(`);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// since you updated the local variable above, this remote update will
|
||||
// get picked up by the remote subscription below.
|
||||
|
Loading…
x
Reference in New Issue
Block a user