WIP: ngrxのexample-appをコードリーディングしてみた
ディレクトリ構造
$ tree -d
.
└── src
├── app
│ ├── auth
│ │ ├── actions
│ │ ├── components
│ │ │ └── __snapshots__
│ │ ├── containers
│ │ │ └── __snapshots__
│ │ ├── effects
│ │ ├── models
│ │ ├── reducers
│ │ │ └── __snapshots__
│ │ └── services
│ ├── books
│ │ ├── actions
│ │ ├── components
│ │ ├── containers
│ │ │ └── __snapshots__
│ │ ├── effects
│ │ ├── guards
│ │ ├── models
│ │ └── reducers
│ │ └── __snapshots__
│ ├── core
│ │ ├── actions
│ │ ├── components
│ │ ├── containers
│ │ ├── effects
│ │ ├── reducers
│ │ └── services
│ ├── material
│ ├── reducers
│ └── shared
│ └── pipes
├── assets
└── environments
36 directories
コンポーネント
containers
$ tree -d
.
└── src
├── app
│ ├── auth
│ │ ├── actions
│ │ ├── components
│ │ │ └── __snapshots__
│ │ ├── containers
│ │ │ └── __snapshots__
│ │ ├── effects
│ │ ├── models
│ │ ├── reducers
│ │ │ └── __snapshots__
│ │ └── services
│ ├── books
│ │ ├── actions
│ │ ├── components
│ │ ├── containers
│ │ │ └── __snapshots__
│ │ ├── effects
│ │ ├── guards
│ │ ├── models
│ │ └── reducers
│ │ └── __snapshots__
│ ├── core
│ │ ├── actions
│ │ ├── components
│ │ ├── containers
│ │ ├── effects
│ │ ├── reducers
│ │ └── services
│ ├── material
│ ├── reducers
│ └── shared
│ └── pipes
├── assets
└── environments
36 directories
containers
Storeの操作を担う。
必要な値をStoreから取得し、componentsに実装した子コンポーネントに値を渡す。
また、子コンポーネントからemit
された場合、Storeにdispatch
する。
いわゆる、ページコンポーネントって言うやつ。
components
componentsにはStoreに値を保存したり、取得したりする処理は実装しない。
@Input
を使って親コンポーネントから値を受け取り、それを表示する。
ユーザーの操作は@Output
を使ってcontainers
にemit
する。
モデル
モデルは、modelsフォルダにinterface
を使って実装する。
テストで使うために、モックもここで定義している。
サービス
HttpClient
使う処理はやっぱりここに書くよね。localStorage
とかも。
あとサービスはコンポーネントからは呼び出してなかった。GUARDからはいくつか呼び出しているところはあった。
ガード
booksのガードはguardsに実装されてるけど、authのガードはservicesに実装されている。
何でですかね?authのガードはだいたいExternal API叩くから?
ACTION
※ 何をもって分けているのかまだ読み解けてないのです。テストコード読んだら追記します。
xxxxx.actions.ts
コンポーネント、EFFECTS、ガードとかから呼び出されてるっぽい。
xxxxxs-api.actions.ts
EFFECTSから呼び出されるACTIONを定義する。
コンポーネントからは呼び出されない。
collection-api.actions.ts
EFFECTSから呼び出されるACTIONを定義する。
コンポーネントからは呼び出されない。
xxxxx-page.actions.ts
containersに実装されているxxxxx-page.component.ts
に対応している。
EFFECTS
※ EFFECTSもテストコード読んでいるところだよ。まぁでもぱっとみ、collectionのほうはCRUDの操作してるっぽい。
xxxxx.effects.ts
collection.effects.ts
REDUCER
※ REDUCERも(ry
xxxxxs.reducer.ts
collection.reducer.ts
search.reducer.ts
Author And Source
この問題について(WIP: ngrxのexample-appをコードリーディングしてみた), 我々は、より多くの情報をここで見つけました https://qiita.com/shinoshu/items/09970179088351e4981c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .