Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 + Redux (or ngrx/store) folder and file structure

Ref to Angular official site's style guile of file structure:

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

If I would like to implement Redux (or ngrx/store) to my new Angular 4 project, would it be better to structure my application in this way?

    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

Or follow ngrx/store's example (https://github.com/ngrx/example-app), to structure the application in this way?

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

Is there any other better structure?

like image 524
RJ Wiki Avatar asked Mar 29 '17 02:03

RJ Wiki


1 Answers

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

like image 177
Hammad Tariq Avatar answered Oct 20 '22 01:10

Hammad Tariq