service from documentation creates async bug at startup
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- angular, typescript
- Ambito
- documentation, mobile-dev
Direzione di ricerca
Inizia con l’esempio del servizio di storage Angular in README.md e confronta l’inizializzazione del suo costruttore con quella del servizio mostrato nell’issue. Aggiorna la documentazione in modo che le letture iniziali dello storage attendano l’inizializzazione, quindi verifica che l’esempio non restituisca più undefined quando lo storage viene consultato durante l’avvio dell’app.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
From my testing of the example service in the documentation, it seems that it contains a bug.
The constructor calls init() without async (because it's not supported in a constructor):
constructor(private storage: Storage) {
this.init();
}
However, that means that if your app is relying on the storage very early on, you are going to get back undefined from a get.
For me, I have a tutorial guard set up which checks if the tutorial has been completed to decide if it should show the homepage or redirect to the tutorial slider page. It was always showing the tutorial because the result was undefined.
I've improved the service so that it takes a similar approach to the way that Ionic Storage is actually written; which is checking if the storage is initialised before trying to operate on it.
That way it can await the proper completion of the storage:
import { Injectable } from '@angular/core';
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
import { Storage } from '@ionic/storage-angular';
@Injectable({
providedIn: 'root'
})
export class StorageService {
private _storage: Storage | null = null;
constructor(private storage: Storage) {
}
async init() {
if(this._storage != null) {
return;
}
await this.storage.defineDriver(CordovaSQLiteDriver);
const storage = await this.storage.create();
this._storage = storage;
}
public async set(key: string, value: any): Promise<any> {
await this.init();
return await this._storage?.set(key, value);
}
public async get(key: string): Promise<any> {
await this.init();
return await this._storage?.get(key);
}
}
- Lingua principale
- TypeScript
- Stelle
- 455
- Fork
- 97
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ionic-team/ionic-storage
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
ionic-team/ionic-storage#326 · 1 commento ·
-
CREATE YOUR OWN LOCALSTORAGEAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
ionic-team/ionic-storage#325 · 2 commenti ·
-
indexeddb issue on iOS 18+Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
ionic-team/ionic-storage#324 · 4 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
ionic-team/ionic-storage#323 · 2 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
ionic-team/ionic-storage#322 · 1 commento · 8 reazioni ·
Tutte le issue di ionic-team/ionic-storage
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
braintrustdata/braintrust-sdk-javascript#2659 ·
I maintainer di solito rispondono entro 1 giorno
-
body-parser 2.3.0 in the published ai-dial-chat-bff image is vulnerable (CVE-2026-111181, HIGH)Forse già presa @illya-havsiyevych l’ha presa oggi. Apertabug
Difficoltà 1/5 1-3 ore Idoneità per principianti 87/100
epam/ai-dial-chat#9566 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
はさみアイコンを修正するApertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
resource.reload() while params is in error switches the resource to 'idle' instead of retryingApertaarea: core
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno