首页 > 解决方案 > 当使用延迟加载 Angular 6 时,ngrx 的最佳文件夹结构是什么?

问题描述

我有一个使用延迟加载的 Angular 6 应用程序。我的文件夹结构如下所示:

src
  app
    main
      products
      invoices
      customers
      suppliers
    core
      header
      footer
      services
      core.module.ts
    shared
    app-routing.module.ts
    app.component.html
    app.component.css
    app.component.spec.ts
    app.component.ts

我遵循了推荐的延迟加载文件夹结构(这里,文件夹下的每个文件main夹都是它自己的模块部分)。

如果我想合并ngrx,我看到了关于在哪里包含 store、reducers 等的不同意见。我读过的一篇文章说要添加一个store文件夹并在其中包含所有 ngrx 片段。我读到的另一篇文章说将 ngrx 片段添加到每个模块/部分。

这里还有另一篇stackoverflow文章:使用ngrx的应用程序的最佳结构是什么?谈论ngrx文件夹结构,但没有提到延迟加载。

使用延迟加载时,是否有推荐的方式来构建 ngrx?为每个模块添加一个包含 reducer、action 等的 store 或者创建一个包含所有内容的巨大 store 文件夹是否更有意义?这个应用程序不是太大;它更像是一个中型应用程序。

谢谢!

标签: javascriptangularngrx

解决方案


绝对将 ngrx 片段分别添加到每个模块中。它为您提供了良好的结构,并且每个模块都是独立的。此外,每个模块中的 ngrx 存储也可以延迟加载,因此只有在加载模块时才会出现状态。

更多详细信息:https ://medium.com/@AnkurRatra/lazy-loading-of-modules-with-ngrx-store-4th-version-angular-2-23c93295d4e8


推荐阅读