小编Phi*_*hil的帖子

为什么ngrx/store示例应用程序使用多个商店?(如何设计商店)

我试图制作一个相当大的,可扩展的应用程序,我被告知最好的做法是让一个存储整个应用程序的当前全局状态(包括瞬态/删除重载和会话持久数据),即使它被分成多个模块.

现在我想知道为什么你可以在ngrx/store-website上找到的ngrx/store 的示例应用程序使用多个商店; 每个reducer都有一段这样的代码:

export interface State {
  ids: string[];
  entities: { [id: string]: Book };
  selectedBookId: string | null;
};

export const initialState: State = {
  ids: [],
  entities: {},
  selectedBookId: null,
};
Run Code Online (Sandbox Code Playgroud)

那么为什么官方指南不按大多数人的建议使用单一商店?或者只要所有减速器属于一个模块,它是否被视为单个商店?如果没有,我如何实现一个单一的中央存储?我的想法是使用Store generic并将其变体放入表中.另一个选项是使用一个单独的JS对象,其属性使用reducer-actions更新.无论哪种方式,您必须在表或对象中具有一些结构.对此有什么最佳做法吗?你知道一个更好的示例应用程序吗?

react-router redux ngrx react-redux angular

7
推荐指数
1
解决办法
6770
查看次数

强制浏览器在Angular环境中清除缓存

有一个流行的问题是如何在VanillaJS应用程序中强制清除浏览器的缓存,一般的共识是,将.js脚本的名称或脚本参数设置为新值:强制浏览器清除缓存

我如何使用Angular实现这一点(目前在AngularCLI/Webpack构建中为5.1),因此每次我在生产中发布代码(使用AOT)时,都会构建一个新版本?我会使用日期散列而不是索引,但主要问题是:我在哪里可以设置它(例如脚本名称/参数)?在开发中,CLI负责重建应用程序,这不是问题,只是在生产中!

javascript caching cache-invalidation angular

7
推荐指数
1
解决办法
1万
查看次数

Angular/Karma 中的模拟文档

如何在 Angular 中模拟 DOCUMENT(HTMLDocument 的影子表示)?实现是在构造函数中使用 this:

@Inject(DOCUMENT) private document: Document
Run Code Online (Sandbox Code Playgroud)

在查看了如何在 Angular 2 服务中注入文档后,我已将其放入我的 .spec 设置中:

const lazyPath = 'dummy';
const pathname = `/${lazyPath}`;
const document = { location: { pathname } as Location } as Document;
beforeEachProviders(() => ([ {provide: DOCUMENT, useValue: document} ]));
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

ERROR in ./src/app/main/components/app-lazy/app-lazy.component.spec.ts
Module not found: Error: Can't resolve '@angular/core/testing/src/testing_internal' in '...'
resolve '@angular/core/testing/src/testing_internal' in '....'
  Parsed request is a module
  using description file: .../package.json (relative path: ...)
    Field 'browser' doesn't contain …
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-runner karma-jasmine angular

7
推荐指数
3
解决办法
2万
查看次数

Angular Universal Firebase:没有InjectionToken MODULE_MAP的提供者

我为什么得到

Error: StaticInjectorError(AppServerModule)[NgModuleFactoryLoader -> InjectionToken MODULE_MAP]: 

  StaticInjectorError(Platform: core)[NgModuleFactoryLoader -> InjectionToken MODULE_MAP]: 

    NullInjectorError: No provider for InjectionToken MODULE_MAP!
Run Code Online (Sandbox Code Playgroud)

什么时候尝试使用firebase进行部署?

我确实用过

extraProviders: [

  provideModuleMap(LAZY_MODULE_MAP)

]
Run Code Online (Sandbox Code Playgroud)

并在我的app-server.module我导入ModuleMapLoaderModule(顺便说一下,我尝试以不同的顺序导入ServerModule和AppModule,我被告知它可能是问题,但它没有用):

@NgModule({

  imports: [

    ServerModule,

    AppModule,

    ModuleMapLoaderModule,

  ],

  bootstrap: [AppComponent],

})

export class AppServerModule { }
Run Code Online (Sandbox Code Playgroud)

main.bundle.js包含这个:

Object.defineProperty(exports, "__esModule", { value: true });

var app_server_module_ngfactory_1 = __webpack_require__("./src/app/app.server.module.ngfactory.js");

exports.AppServerModuleNgFactory = app_server_module_ngfactory_1.AppServerModuleNgFactory;

var __lazy_0__ = __webpack_require__("./src/app/features/blog/blog.module.ngfactory.js");

var app_server_module_1 = __webpack_require__("./src/app/app.server.module.ts");

exports.AppServerModule = app_server_module_1.AppServerModule;

exports.LAZY_MODULE_MAP = { "app/features/blog/blog.module#BlogModule": __lazy_0__.BlogModuleNgFactory };
Run Code Online (Sandbox Code Playgroud)

main.bundle.js是否正确导入firebase脚本,因为如果我更改了一些字母require(...),我会收到一个错误,该文件未知.那有什么不对LAZY_MODULE_MAP?它看起来像是一个字符串路由到工厂的map/js-object,它会被导出.那为什么不能provideModuleMap正确解决呢?在BlogModule只有一个Hello-世界存根组件的声明. …

firebase google-cloud-functions angular-universal angular

6
推荐指数
2
解决办法
735
查看次数

Conditional Styling in Pandas using other columns

I've searched and can't seem to find an answer on this anywhere, so hopefully it's possible. I have a dataframe, for simplicity I'll include an abbreviated version below. What I'd like to do is apply a custom formula for styling, or style one particular column based on the values in another column.

在此处输入图片说明

Using this as an example, I'd like to highlight the Current column's cells where the Diff > Historic Standard Dev in that row.

I've explored the style.apply approaches, …

python conditional-formatting styling pandas

6
推荐指数
1
解决办法
5372
查看次数

Jest + IntelliJ (IDEA) => 错误:async() 测试助手需要区域但找不到

当我从命令行对 Angular-Libs 运行 Jest-Unit 测试时,它们工作正常。当我在单个测试中从 IntelliJ(版本 2019.1)运行它们时,它们仅在我不使用 async() 时才起作用。

这很奇怪,因为我的 angular.json 包含以下内容:

    "auth": {
      "root": "libs/auth",
      "sourceRoot": "libs/auth/src",
      "projectType": "library",
      "prefix": "auth",
      "architect": {
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "libs/auth/tsconfig.lib.json",
              "libs/auth/tsconfig.spec.json"
            ],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "@nrwl/builders:jest",
          "options": {
            "jestConfig": "libs/auth/jest.config.js",
            "tsConfig": "libs/auth/tsconfig.spec.json",
            "setupFile": "libs/auth/src/test-setup.ts"
          }
        }
      },
      "schematics": {
        "@nrwl/schematics:component": {
          "styleext": "scss"
        }
      }
    },
Run Code Online (Sandbox Code Playgroud)

并且在test-setup.ts(在 lib 内部)中import 'jest-preset-angular';包含,它执行:

require('core-js/es6/reflect'); 
require('core-js/es7/reflect'); 
require('zone.js/dist/zone.js');    
require('zone.js/dist/proxy.js');   
require('zone.js/dist/sync-test');  
require('zone.js/dist/async-test'); 
require('zone.js/dist/fake-async-test');    
require('./zone-patch');
Run Code Online (Sandbox Code Playgroud)

在设置过程中。 …

intellij-idea webstorm jestjs angular

6
推荐指数
0
解决办法
2157
查看次数

如何按顺序使用 RxJS observables?

事情是这样的:我有一个 HTTP get 请求,它返回一个 JSON 对象列表。使用 RxJS 我订阅接收该列表的数据。现在,对于该列表中的每个对象,我想执行另一个 HTTP 请求,然后将该请求的结果放入一个数组中。

到目前为止,我已经能够做到这一点,但我似乎无法弄清楚如何用数据维护初始列表的顺序。这可能与整个 Observable 机制是异步的这一事实有关。

这是我的代码:

    ngOnInit(): void {
    this.shiftInformationService.getShifts("2016-11-03T06:00:00Z", "2016-11-06T06:00:00Z")
        .subscribe(shifts => {
            shifts.forEach(shift => {
                this.addDataToAreaChart(shift.startDateTime, shift.endDateTime, shift.description);
            });
        });

}

addDataToAreaChart(startDate: string, endDate: string, description: string) {
    this.machineStatisticsService
        .getCumulativeMachineStateDurations(startDate, endDate)
        .subscribe(s => {
            this.areaChartData = [];
            this.areaChartData.push(new AreaChartData(startDate, endDate, description, s));
        });
}
Run Code Online (Sandbox Code Playgroud)

我想要的是shifts.forEach在推送areaChartData数组中的数据时保持从循环调用的顺序。

有任何想法吗?帮助将不胜感激!

更新:解决了!

最终代码:

ngOnInit(): void {
    var startDate = new Date();
    startDate.setDate(startDate.getDate() - 3);

    this.shiftInformationService.getShifts(DateUtil.formatDate(startDate), DateUtil.formatDate(new Date()))
        .subscribe(shifts => {
            Observable.from(shifts) …
Run Code Online (Sandbox Code Playgroud)

javascript rxjs typescript angular

5
推荐指数
1
解决办法
2万
查看次数

无法访问docker容器中的服务器

我开始使用docker图像

docker run --interactive --tty node_web_1
Run Code Online (Sandbox Code Playgroud)

并且容器内的运行服务器成功打印

Running on http://localhost:8080
Run Code Online (Sandbox Code Playgroud)

在控制台中.我在Dockerfile中暴露了端口8080.所以在我的理解中,当我在windows中的浏览器中调用http:// localhost:8080时,我应该访问容器中的服务器,对吗?我得不到回复....

我如何找到错误?我执行了命令

docker-machine ls
Run Code Online (Sandbox Code Playgroud)

如此建议如何从主机访问Docker容器的Web服务器,但显然我没有运行docker-machines?这些机器是什么?我需要它们吗?我只安装了用于安装Windows的docker,没有附加的软件包或shell.

deployment node.js docker

5
推荐指数
1
解决办法
1088
查看次数

Angular Universal:提供关键CSS并延迟非关键

这基本上是我正在使用的代码,并且灯塔说我的css包正在延迟我的初始加载。

那么我该如何链接到critical.scss

<head><style>DONT_WANT_TO_WRITE_STUFF_INLINED</style>...</head>

有没有比https://www.npmjs.com/package/critical更好的解决方案,或者内联所有内容?

以及如何延迟主要styles.scss的加载,直到预渲染的Universal内容加载到浏览器中?angular-cli.json中服务器应用程序的配置不包含stylesassets,所以我不明白为什么最初加载styles.scss

css lighthouse progressive-web-apps angular-universal angular

5
推荐指数
1
解决办法
424
查看次数

Flutter 中的 Widget 是什么?

Flutter 教程到处都使用“Widget”这个词。在这种情况下什么是小部件?我能在 SO 上找到的最接近的问题在这里:什么是 Android 中的小部件?

但它是关于 Android 而不是 Flutter(它为 Android 和 iOS 构建,因此在两种上下文中都定义了小部件)并且答案有点令人困惑。一个人说 Widget 就像一个按钮(所以我想到了一些 Ui 包/框架的 Ui 组件),另一个人说它就像一个应用程序,因为它可以在任何地方运行并占据整个屏幕。那么来自 WebDevelopment,我可以假设 Widget 类似于 WebComponent 吗?

它是一段独立的代码,不依赖于其他组件,但需要在环境中引导?这个假设是真的吗?安卓和iOS都可以吗?

android ios flutter

5
推荐指数
2
解决办法
3991
查看次数