service from documentation creates async bug at startup
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- angular, typescript
- Área
- documentation, mobile-dev
Línea de trabajo
Comienza con el ejemplo del servicio de almacenamiento de Angular en README.md y compara la inicialización de su constructor con la del servicio mostrado en el issue. Actualiza la documentación para que las lecturas tempranas del almacenamiento esperen a la inicialización y, después, verifica que el ejemplo ya no devuelva undefined cuando se accede al almacenamiento durante el inicio de la app.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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);
}
}
- Lenguaje dominante
- TypeScript
- Estrellas
- 456
- Forks
- 97
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ionic-team/ionic-storage
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
ionic-team/ionic-storage#326 · 1 comentario ·
-
CREATE YOUR OWN LOCALSTORAGEAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
ionic-team/ionic-storage#325 · 2 comentarios ·
-
indexeddb issue on iOS 18+Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
ionic-team/ionic-storage#324 · 4 comentarios · 1 reacción ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
ionic-team/ionic-storage#323 · 2 comentarios · 1 reacción ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
ionic-team/ionic-storage#322 · 1 comentario · 8 reacciones ·
Todos los issues de ionic-team/ionic-storage
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
cline/mcp-marketplace#2932 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
lingdojo/kana-dojo#32188 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Portkey-AI/gateway#1844 ·
Los mantenedores suelen responder en 1 día
-
needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 61/100
rjsf-team/react-jsonschema-form#5495 ·
Los mantenedores suelen responder en 2 días