【问题标题】:Angular 4 + Redux (or ngrx/store) folder and file structureAngular 4 + Redux(或ngrx/store)文件夹和文件结构
【发布时间】: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.tsfeature.reducer.tsfeature.selectors.ts
  • 你可能想看看我制作的 github 存储库,以展示我喜欢这样做:github.com/maxime1992/angular-ngrx-starter

标签: javascript angular redux ngrx


【解决方案1】:

项目根目录

├── src/
│   ├── app/
│   │  ├──stores/
│   │  │  ├── heros/
│   │  │  │  ├── heros.actions.ts|reducer|effects|store.ts
│   │  │  │ 
│   │  │  │── ..../
│   │  │  │  ├── .....
│   │  │  
│   │  ├── containers/
│   │  │  ├── heros/
│   │  │  │  ├── heros.component.ts|html|css|spec.ts
│   │  │  │  │  └── ......
│   │  │  
│   │  │
│   │  ├── components/
│   │  │  ├── hero-list/
│   │  │  │  │  ├── hero-list.component.ts|html|css|spec.ts
│   │  │  │  │  └── .......
│   │  │  ├── ....

我一直在使用第二种结构,但是随着我的应用程序的增长,它变得难以维护,然后我以这种方式重构了结构,这个结构的优点是,如果将来你决定删除或编辑 ngrx您需要做的就是删除或编辑 stores 文件夹。

注意:

  • containers 文件夹包含我的智能组件

  • components 文件夹包含我的哑组件

【讨论】:

  • heros.store.ts 是型号吗?
  • 这里的模型(实体、接口)是什么?
猜你喜欢
  • 2018-03-15
  • 2020-11-19
  • 2018-01-29
  • 1970-01-01
  • 1970-01-01
  • 2016-03-20
  • 1970-01-01
  • 2019-06-14
  • 1970-01-01
相关资源
最近更新 更多