angular / angular/angularfire

Providers and Injections should be by name or at least by Map<string,type> and not by a simple Array<type>

オープン
#3,271 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
7.8k
フォーク
2.2k
平均マージ
22時間 28分
マージ済み PR(30日)
6

説明

### Version info

**Angular:** 14.2

**Firebase:** 9.9.3

**AngularFire:** 7.4.1

**Other (e.g. Ionic/Cordova, Node, browser, operating system):** Irrelevant

### Expected behavior

Provide / Injection by name or Map where the string is the name to find easy and clean your angular firebase components or have a function to findByName(name: string).

I'm not talking only about Auth, I'm talking regarding all your types but I use Auth for the examples

``` typescript
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(config)), // default app
provideFirebaseApp(() => initializeApp(config2, 'app2')),
provideFirebaseApp(() => initializeApp(config3, 'app3')),
provideAuth(() => getAuth()), // from default app
provideAuth(() => getAuth(getApp('app2'))),
provideAuth(() => getAuth(getApp('app3'))),
],
})
```

One of the next options should be there to be use it easy:

**Option 1** - Could be work with your actual Array but I think that search this search byName in this array is dirty and I recommend to not reinvent the wheel and use a Map
``` typescript
constructor(
private authApp: Auth,
private authApp2: AuthInstances.getByName('app2'),
private authApp3: AuthInstances.getByName('app3'),
) { }
```

**Option 2** - Could be work with your actual Array but again I recommend to not reinvent the wheel and use a Map
``` typescript
constructor(private authInstances: AuthInstances) { }

doWithAuth(name: string) {
const auth = this.authInstances.getByName(name)
// the things that you want to do with your auth
}
```

**Other options** - Any idea that let you select your angular fire element more easy and clean that now.

### Actual behavior

Provide / Injection is a simple Array and does not have any method to select by name.

``` typescript
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(config)), // default app
provideFirebaseApp(() => initializeApp(config2, 'app2')),
provideFirebaseApp(() => initializeApp(config3, 'app3')),
provideAuth(() => getAuth()), // from default app
provideAuth(() => getAuth(getApp('app2'))),
provideAuth(() => getAuth(getApp('app3'))),
],
})
```

``` typescript
private authMap: Map;
constructor(private authInstances: AuthInstances) {
this.authInstances.forEach(auth => {
this.authMap.set(auth.name,auth);
});
}
```

### Feedback

I think that your Provide / Injection should work with maps or with something that can be select the future injection by name.

Another important thing, is that you must declare a default app, if not the AuthInstaces fail because default app is not initializate and then to find this default app is so ugly `name: "[DEFAULT]"`

To finish, you cannot import only one auth if your auth is not default, because you have a way to import default and to import an array with default and another auths. Is there a way to inject `auth: Auth` by name and avoid import all the array?

Issue post from discussion: _Originally posted by @todosybuenrollo in https://github.com/angular/angularfire/discussions/1026#discussioncomment-3613308_

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、issue に記載されているエントリポイント provideFirebaseApp、provideAuth、AuthInstances を追跡し、デフォルトおよび名前付きの Firebase アプリがどのように解決されるかを確認します。名前付き injection と map ベースの API のどちらを選ぶか決める前に、現在の injection の動作と関連するテストがあればそれらを確認します。完了条件は、デフォルトアプリの動作を維持しながら、コンシューマーが配列を手動で走査せずに、名前でデフォルト以外の Auth インスタンスを選択できることです。

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

評価

技術スタック
angular, firebase, typescript
領域
backend-api-design
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

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

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