javascript - Angular 4 + Redux(或 ngrx/store)文件夹和文件结构

标签 javascript angular redux ngrx

引用Angular官网的文件结构风格:

https://angular.io/docs/ts/latest/guide/style-guide.html#!#04-06

如果我想在我的新 Angular 4 项目中实现 Redux(或 ngrx/store),以这种方式构建我的应用程序会更好吗?

    project root

    ├── 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
    │   │  │  │  │  └── .......
    │   │  │  ├── ....

I have been using second structure but as my app grows, it was getting difficult to maintain, and then I refactored the structure in this way, the plus point of this structure is, if in future you decide to remove or edit ngrx all you need to do is remove or edit the stores folder.

Note:

- containers folder hold my smart components

- components folder hold my dumb components

或者按照 ngrx/store 的示例(https://github.com/ngrx/example-app),以这种方式构建应用程序?

    project root
    ├── src/
    │   ├── app/
    │   │  ├── actions/
    │   │  │  ├── hero.js
    │   │  │  ├── hero-list.js
    │   │  │  └── ......
    │   │  ├── reducers/
    │   │  │  ├── hero.js
    │   │  │  ├── hero-list.js
    │   │  │  └── ......
    │   │  ├── components/
    │   │  │  ├── heros/
    │   │  │  │  ├── hero/
    │   │  │  │  │  ├── hero-list.component.ts|html|css|spec.ts
    │   │  │  │  │  └── ......
    │   │  │  │  ├── hero-list/
    │   │  │  │  │  ├── hero-list.component.ts|html|css|spec.ts
    │   │  │  │  │  └── ......
    │   │  │  ├── ......

还有其他更好的结构吗?

最佳答案

项目根

├── 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您需要做的就是删除或编辑商店文件夹。

注意:

  • containers 文件夹存放我的智能组件

  • components 文件夹存放我的dumb组件

关于javascript - Angular 4 + Redux(或 ngrx/store)文件夹和文件结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43083023/

相关文章:

javascript - 无法从 VALUE_STRING 中反序列化 java.util.List 的实例

javascript - typescript 上有一个 `Object.values()` 吗?

angular - 如何在我的 Angular 2 CLI 构建中添加更少的内容?

json - Angular 5,rxjs 映射到 json,类型“对象”上不存在 'json'

reactjs - Immer 是否允许我们在 redux reducer 中存储类实例?

reactjs - 类型错误 : middleware is not a function

javascript - 组件未完全渲染且不随 State 的变化而变化

javascript - 在屏幕上移动图像

javascript - 动画无法按设置运行

javascript - 如何使用 JSON 数组中的值更改 $.get 中的数据元素?