Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

service from documentation creates async bug at startup

オープン
#229 コメント 7 件 リアクション 42 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
angular, typescript

調査の方向性

README.md の Angular ストレージサービスの例から始め、そのコンストラクターの初期化を issue に示されているサービスと比較します。初期のストレージ読み取りが初期化を待機するようにドキュメントを更新し、その後、アプリの起動中にストレージへアクセスしても例が undefined を返さなくなったことを確認します。

索引モデルが issue の本文から書いたものです。

説明

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);
  }
}
主要言語
TypeScript
スター
456
フォーク
97
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ionic-team/ionic-storage のほかの issue

ionic-team/ionic-storage の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。