簡體   English   中英

StoreModule.forRoot() 中的 Reducer 名稱

[英]Reducer name in StoreModule.forRoot()

我的問題是為什么下面兩個突出顯示的count的名稱需要相同才能使應用程序正常工作? 文檔說 forRoot 將減速器作為參數,但為什么 forRoot 中減速器的名稱應該與 state 相同(在這種情況下計數)? 我在文檔中的任何地方都沒有看到這一點,謝謝!

進口:[BrowserModule, StoreModule.forRoot({ count : counterReducer })],

構造函數(私人商店:Store<{ count : number }>){ this.count$ = store.select('count'); }

(示例來自https://ngrx.io/guide/store

forRoot (和forFeature )構建 state 樹,在此示例中,您最終得到以下 state 樹:

{
  count: 0
}

select從 state 樹中讀取,您必須從頂層開始,這就是為什么需要count ,因為它從 Z9ED39E2EA931586B6A985A6942EF7 樹中讀取count屬性。

一個更大的 state 的例子:

{
  customers: {
    persons: {
      ...
    }
  }
}

將導致以下 select 獲取人員

store.select('customers', 'persons')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM