ngrx初識
在使用之前需要安裝ngrx
npm install @ngrx/store --save
或者
yarn add @ngrx/store
ngrx/store:保存了ReduxAPI的核心概念,使用RxJS擴展的Redux實現。使用可觀察對象來簡化了監聽事件的訂閱等操作。
dispatch&reducer&state
dispatcher,reducer,state都是基于BehaviorSubject的,BehaviorSubject:儲存著要發射給消費者的最新的值。無論何時一個新的觀察者訂閱它,都會立即接受到這個來自BehaviorSubject的”當前值”。
Store
官方英文解釋:
Like a traditional database represents the point of record for an application, your store can be thought of as a client side ‘single source of truth’, or database. By adhering to the 1 store contract when designing your application, a snapshot of store at any point will supply a complete representation of relevant application state. This becomes ex