【发布时间】:2017-08-22 07:43:45
【问题描述】:
参考Angular官网的文件结构风格诡计:
https://angular.io/docs/ts/latest/guide/style-guide.html#!#04-06
如果我想在我的新 Angular 4 项目中实现 Redux(或 ngrx/store),以这种方式构建我的应用程序会更好吗?
项目根 ├── src/ │ ├── app/ │ │ ├──专卖店/ │ │ │ ├── 英雄/ │ │ │ │ ├── heros.actions.ts|reducer|effects|store.ts │ │ │ │ │ │ │ │── ..../ │ │ │ │ ├── ..... │ │ │ │ │ ├── 容器/ │ │ │ ├── 英雄/ │ │ │ │ ├── heros.component.ts|html|css|spec.ts │ │ │ │ │ └── ...... │ │ │ │ │ │ │ │ ├── 组件/ │ │ │ ├── hero-list/ │ │ │ │ │ ├── hero-list.component.ts|html|css|spec.ts │ │ │ │ │ └── ....... │ │ │ ├── .... 我一直在使用第二种结构,但是随着我的应用程序的增长,它变得难以维护,然后我以这种方式重构了结构,这种结构的优点是,如果将来你决定删除或编辑所有你需要的 ngrx要做的是删除或编辑存储文件夹。 笔记: - 容器文件夹包含我的智能组件 - 组件文件夹包含我的愚蠢组件或者按照ngrx/store的例子(https://github.com/ngrx/example-app),以这种方式构建应用程序?
项目根 ├── src/ │ ├── app/ │ │ ├── 动作/ │ │ │ ├── hero.js │ │ │ ├── hero-list.js │ │ │ └── …… │ │ ├── 减速机/ │ │ │ ├── hero.js │ │ │ ├── hero-list.js │ │ │ └── …… │ │ ├── 组件/ │ │ │ ├── 英雄/ │ │ │ │ ├── 英雄/ │ │ │ │ │ ├── hero-list.component.ts|html|css|spec.ts │ │ │ │ │ └── ...... │ │ │ │ ├── hero-list/ │ │ │ │ │ ├── hero-list.component.ts|html|css|spec.ts │ │ │ │ │ └── ...... │ │ │ ├── ......还有其他更好的结构吗?
【问题讨论】:
-
使用 app/ 或 src/ 作为应用程序根文件夹...(src/app 没有意义,除非您有 src/app2、src/app3,在这种情况下,是将这些应用程序分成单独的存储库)
-
我会采用第一种方式,但这只是个人喜好/意见。因此投票接近。
-
未来,功能模块将能够添加自己的减速器。出于这个原因,我在每个模块中都有一个目录用于存储
/app/feature/store,它包含feature.actions.ts、feature.reducer.ts和feature.selectors.ts -
你可能想看看我制作的 github 存储库,以展示我喜欢这样做:github.com/maxime1992/angular-ngrx-starter
标签: javascript angular redux ngrx