Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder structure, modules/ducks, best practices #169

Closed
justingreenberg opened this issue Sep 7, 2015 · 5 comments
Closed

Folder structure, modules/ducks, best practices #169

justingreenberg opened this issue Sep 7, 2015 · 5 comments

Comments

@justingreenberg
Copy link
Contributor

Thank you so much for putting together this awesome project. As a fresh set of eyes, I have a bit of feedback. Maybe it's just me but I found the project's folder structure to be a little confusing....

Proposed folder structure:

This is overly simplified as I didn't want to put the entire file tree into this discussion, but hopefully you get the idea. Components are contained within folders, aggregated and exported from root for destructured imports (similar to material-ui components).

./react-redux-universal-hot-example
├── bin
├── src
   ├── components // eg. import { InfoBar } from '../components'
      ├── CounterButton
      ├── GithubButton
      ├── InfoBar
      ├── MiniInfoBar
      ├── SurveyForm
      ├── WidgetForm
      └── __tests__
   ├── containers // more descriptive, used in official docs/examples...
      ├── About
      ├── App
      ├── Home
      ├── Login
      ├── LoginSuccess
      ├── NotFound
      ├── RequireLogin
      ├── Survey
      ├── Widgets
      └── __tests__
          └── routes.js // routes defined in root
   ├── redux
      ├── init.js
      ├── middleware
         └── clientMiddleware.js  // etc
      └── modules // (action/creator/reducer/selector bundles)
          ├── auth.js
          ├── counter.js
          ├── reducer.js  
          ├── info.js
          └── widgets.js
   ├── server
      ├── middleware
      └── actions // proxy to separate REST api...
   └── utils
      ├── validationUtility.js // utility only (component-level definitions inside respective dir)
       └── createDevToolsWindow.js  // etc
├── static
   ├── dist
   └── images
└── webpack

As you can see, the structure is pretty clean and self-documenting. The only downside is the additional folder nesting, but I think it's well worth it for the sake of maintainability. It may be a little contrived for an example project, but for those using this as a "starter" it will pay dividends down the road. I am setting up webpack aliases so make things easier and reduce some of the import boilerplate. The folder structure above is working in a branch on my local machine, let me know I'd be happy to submit a PR!

Modules/Ducks

I love the concept of encapsulating reducer tuples (plus selectors) into bundles. I know ducks is your project and I totally did not mean to torpedo the name with the proposed folder structure above! I really think "module" or "redux-module" encapsulates the idea in a coherent way that doesn't make newcomers feel like they have to learn even more (imo ducks kinda sounds like another framework or something that would require additional cognitive overhead, but really it's simply bundling reducer logic).

Please let me know if you would any separate PRs for the following, which are also done...

  • Option to open Redux Devtools in a new window (it's so annoying in the application)
  • Minimize bootstrapped data in SSR production mode, and other little optimizations

I will try to help write some some documentation when I have time.

Looking forward to your thoughts. Cheers!

@justingreenberg justingreenberg changed the title Project folder structure Project folder structure proposal, modules/ducks, best practices Sep 7, 2015
@justingreenberg justingreenberg changed the title Project folder structure proposal, modules/ducks, best practices Folder structure, modules/ducks, best practices Sep 7, 2015
@erikras
Copy link
Owner

erikras commented Sep 7, 2015

I like this a lot. Especially the use of a water-based weapon to kill ducks. You are probably right, that "ducks" should be only a slang term to refer to the modular tuples. Sure, go ahead and submit a PR.

Yes, both of those additional PRs would be great!

Thanks for putting so much thought and effort into this. 👍

@bdefore
Copy link
Collaborator

bdefore commented Sep 8, 2015

i like this too, i'd been structuring my folder structure similarly in my fork

@jasonkylefrank
Copy link

Hi @justingreenberg and @erikras,

At the risk of sounding rather naive about some Webpack or ES6 (or other?) things, I have a question about how your path-less import statements work.

@justingreenberg, in his original post above, mentioned that (italics added are mine)

"Components are contained within folders, aggregated and exported from root for destructured imports".

This seems to have been implemented in this repo in places like src/components/index.js:

image

Is that all that is needed to enable the path-less import mentioned in the code comments? Or do you also need to set something up an alias or something in the Webpack config? Perhaps Webpack's resolve.modulesDirectories?

image

I see that you do specify src for that property in your webpack config:

image

Is it the combination of what you did in places like src/components/index.js, as well as specifying src in the webpack config's resolve.modulesDirectories that enables the path-less import statements?

@justingreenberg
Copy link
Contributor Author

@jasonkylefrank yes, but the recommended method of resolving project paths is to use resolve.root instead of resolve.modulesDirectories (which i did not know about at the time)

see:
webpack/webpack#472 (comment)
webpack/webpack#1574 (comment)

@jasonkylefrank
Copy link

@justingreenberg Great, thanks for the info!

PabloHidalgo added a commit to PabloHidalgo/angularjs-redux-showcase that referenced this issue May 15, 2016
…y as DUCKS but a more classical naming for easy transition). Based on:

- react-redux-universal-hot-example -  Folder structure, modules/ducks, best practices: erikras/react-redux-universal-hot-example#169

- react-redux-starter-kit - Follow ducks-like architecture: dvdzkwsk/react-redux-starter-kit#248

- react-redux-starter-kit - refactor(redux): use ducks-like architecture: dvdzkwsk/react-redux-starter-kit#265

Removed state data filtering logic from controllers and placed it inside selectors using reselect library for redux.

Adapted components logic to use selectors library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants