0

I am reviewing how the ngrx is implemented in the example app on GH. Can someone please explain why there are two modules in one file at the link below? What reasoning the developer had to have two modules in place of one?

Github link - auth module in ngrx library example app

edit - the same functionality could be implemented with one module itself. why create two modules? what's the functionality split here?

edit-2 - I found the reason for two modules for Auth. The developer needs to export the services such as auth service and auth Guard for use by app module and other modules. For that he created the AuthModule which has forRoot static method for exporting the services.

The other RootAuthModule has the components for html form for getting user input and dispatching the action for authentication. This module is lazy loaded and need not export any components or any services for use by other modules.

PankajSays
  • 965
  • 1
  • 9
  • 12

2 Answers2

3

You can organize your files as you want but remember that placing two modules in one file is not recommended : https://angular.io/guide/styleguide#rule-of-one

Titch
  • 81
  • 1
  • 3
0

Same file

Both modules are small and the developer did not see the need to split it into two separate files. They are pretty similar to each other so it makes sense to have them in the same file. I don't think there's any special reason, as it does not change the big picture at all. If developer feels that at one point they've become too large, they can be separated later.

Two modules

As for why two modules: one is used at the root-level and the other at children level. The most common example of this distinction is using .forRoot and .forChildren with the official RouterModule from @angular/router package. Here, instead of the two static methods, NGRX team has decided to go with a module with forRoot method and another one for children (since it does not need any arguments).

You can read more about the difference between forRoot and forChild here.

Lazar Ljubenović
  • 18,976
  • 10
  • 56
  • 91
  • apart from one file/two file - the same functionality could be implemented with one module itself. why create two modules? what's the functionality split here? – PankajSays Mar 14 '18 at 17:53
  • I found a better explanation of my question. Thanks for your input. :) – PankajSays Mar 15 '18 at 19:50