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