service from documentation creates async bug at startup
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- angular, typescript
- Lĩnh vực
- documentation, mobile-dev
Hướng nghiên cứu
Bắt đầu với ví dụ về storage service của Angular trong README.md và so sánh việc khởi tạo constructor của nó với service được hiển thị trong issue. Cập nhật tài liệu để các lần đọc storage sớm chờ quá trình khởi tạo, sau đó xác minh rằng ví dụ không còn trả về undefined khi storage được truy cập trong lúc app khởi động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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);
}
}
- Ngôn ngữ chính
- TypeScript
- Star
- 456
- Fork
- 97
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/ionic-storage
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
ionic-team/ionic-storage#326 · 1 bình luận ·
-
CREATE YOUR OWN LOCALSTORAGEĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
ionic-team/ionic-storage#325 · 2 bình luận ·
-
indexeddb issue on iOS 18+Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
ionic-team/ionic-storage#324 · 4 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
ionic-team/ionic-storage#323 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
ionic-team/ionic-storage#322 · 1 bình luận · 8 reaction ·
Tất cả issue của ionic-team/ionic-storage
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
better-auth/better-auth#11723 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: docs difficulty: easy documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Worker-Erstellung bricht langsame Git-Worktree-Checkouts nach 20 Sekunden abCó thể đã có người làm @KajoVanBuyten đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
AgentSystemLabs/agent-office#367 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pierrecomputer/pierre#1187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: frontend bug
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
snapotter-hq/SnapOtter#2425 ·
Maintainer thường phản hồi trong vòng 1 ngày