我已经接管了一个现有的 Angular 应用程序,我正在从 5 更新到版本 7。对于状态管理,它使用已更新到版本 9.0 的@angular-redux。但是,保持商店不变会导致应用程序无法加载(没有控制台错误)。
我已经更改了每个史诗中的功能,如终端中所说的代码所示。但是,我还没有找到有关如何调整项目正在运行的主 store.ts 文件的资源,这会破坏应用程序。如果有人知道要在该文件中放入什么以使商店正确设置,请分享。
商店.ts:
import { NgModule } from "@angular/core";
import {
NgReduxModule,
NgRedux,
DevToolsExtension
} from "@angular-redux/store";
import { NgReduxRouterModule, NgReduxRouter } from "@angular-redux/router";
// The top-level reducers and epics that make up our app's logic.
import { IModel, initialData } from "./model";
import { rootReducer } from "./reducer";
import { Epic } from "./epic";
import { StorageService } from "./storage-service";
// DataModels
import { ApplicationStateModule } from "./application-state/module";
import { EntitiesModule } from "./entities/module";
import { LiveDataModule } from "./live-data/module";
import { RouterModule } from "./router/module";
import { StoreSelectors } from "./selectors";
import { TimePeriodModule } from "./time-period/module";
import { TimeSeriesDataModule } from "./time-series-data/module";
import { SelectorsModule } from "../selectors/selectors.module";
import { PointInTimeModule } from "./point-in-time/module";
import { applyMiddleware, createStore } from "redux";
import { createEpicMiddleware } from "redux-observable";
@NgModule({
imports: [
NgReduxModule,
NgReduxRouterModule.forRoot(),
ApplicationStateModule,
EntitiesModule,
LiveDataModule,
RouterModule,
...Module,
...Module,
...Module,
...Module
],
providers: [Epic, StoreSelectors, StorageService]
})
export class Store {
constructor(
public store: NgRedux<IModel>,
devTools: DevToolsExtension,
ngReduxRouter: NgReduxRouter,
rootEpic: Epic,
storageService: StorageService
) {
store.configureStore(
rootReducer,
storageService.fromStore(initialData),
// the commented code below breaks the app if either line is uncommented
// [...rootEpic.createEpics()],
// devTools.isEnabled() ? [devTools.enhancer()] : []
);
if (ngReduxRouter) {
ngReduxRouter.initialize();
}
}
}
以下是特定的 epic.ts 文件之一的示例:
import { Injectable } from '@angular/core';
import { Actions } from './actions';
import { Actions as ApplicationStateActions } from '../applicationstate/actions';
import { createEpicMiddleware } from 'redux-observable';
import { createStore, applyMiddleware } from 'redux';
import { rootReducer } from '../reducer';
@Injectable()
export class Epic {
constructor(
private actions: Actions,
private applicationStateActions: ApplicationStateActions
) {}
load = (action$) =>
action$
.ofType(Actions.SET_DATES_AVAILABLE)
.map((action) => {
return this.actions.setUnit(2);
})
.ofType(Actions.SET_UNIT)
.map((action, state) => {
return this.applicationStateActions.updateTimePeriodStatus('ready');
})
public createEpics() {
const epicMiddleware = createEpicMiddleware();
const store = createStore(rootReducer, applyMiddleware(epicMiddleware));
// tslint:disable-next-line: no-void-expression
return [epicMiddleware.run(this.load)];
//below is the original way it was, above is the change the terminal said to do,
//see https://github.com/redux-observable/redux-observable/blob/master/MIGRATION.md
// return [createEpicMiddleware(this.load)];
}
}