结构1
reducers
index.ts //Combine all reducers
user.reducer.ts
product.reducer.ts
actions
index.ts //Combine all actions
user.action.ts
product.action.ts
effects
index.ts //Combine all effects
user.effect.ts
product.effect.ts
selector
//Combine all selectors
user.selector.ts
product.selector.ts
OR
user
user.reducer.ts
user.action.ts
user.effect.ts
user.selector.ts
product
product.reducer.ts
product.action.ts
product.effect.ts
product.selector.ts
reducers.ts //Combine all reducers
actions.ts //Combine all actions
effects.ts //Combine all effects
selectors.ts //Combine all selectors
当在应用程序的多个 SMART 组件中使用减速器、操作或其他组件时,我发现第一个结构非常适合相当小的应用程序。
尽管它促进了关注点分离,但我发现在各个目录之间跳转相当乏味。
通常,与,即user.reducer.ts
,将涉及使用其他文件:效果、动作等。因此,第二种方法似乎更整洁一些。
我想建议一种可能适合的第三种结构,它遵循 angular2 中的“桶”方法:
- store
- user
- index.ts
- user.actions.ts
- user.effects.ts
- user.reducer.ts
- user.reducer.spec.ts
// the store definition file - will expose reducer, actions etc..
// for connecting those to the app in the bootstrap phase
- index.ts
通过这种结构,user目录是一个桶,它公开了各种逻辑组件,只需导入用户即可单独导入这些组件,即:
import { reducer as UserReducer } from '../store/user';
// or
import { UserReducer } from '../store/user'
我正在我的开源媒体播放器应用程序中尝试这些方法 -回声播放器 http://echoesplayer.com - http://github.com/orizens/echoes-player http://github.com/orizens/echoes-player
正如另一条评论中提到的,这些应用于 echoes 播放器的策略和架构被编译在ngrx 样式指南 http://github.com/orizens/ngrx-styleguide
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)