首页 > 解决方案 > 将 @ngrx-store 移动到新版本

问题描述

我的应用程序中有@ngrx-store,现在我要将动作、减速器和效果更新到最新版本......直到现在,使用旧的动作/减速器/效果一切正常,但现在我无法从中获取数据效果,得到这个错误

错误类型错误:调度期望一个对象,而不是它收到一个函数。如果您使用 createAction 函数,请确保在调度操作之前调用该函数。例如,someAction 应该是 someAction()。

这是我的行动

import { createAction, props } from "@ngrx/store";
import { IAppAll} from "./../../app.model";

export const loadApps = createAction("[App] Load Apps");

export const loadAppsSuccess = createAction(
  "[App] Load AppSuccess",
  props<{ sites: IAppAll[] }>()
);

这是减速机

import { Action, createReducer, on } from "@ngrx/store";
import * as AppActions from "../actions/app.actions";
import { initialState, State } from "../state/site.model";

export const appeFeatureKey = "app";

const appReducer = createReducer(
  initialState,
  on(AppActions.loadApp, state => ({ ...state })),
  on(AppActions.createApp, (state, { app}) => ({ ...state }))
);

export function reducer(state: State | undefined, action: Action) {
  return appReducer(state, action);
}

这是效果

export class AppEffects {
  loadApps$ = createEffect(() =>
    this.actions$.pipe(
      ofType(appActions.loadApps),
      concatMap(() =>
        this.appService
          .getApps()
          .pipe(
            map((apps: IAppAll[]) => appActions.loadAppsSuccess({ apps }))
          )
      )
    )
  );

我的json是这样的

[{key: value, key1: value1},
{key: value, key1: value1}]

此数据在“最后一个”ngrx/store版本 In action <props>is object 上正常工作,但如何更改呢?

谢谢

标签: angulartypescriptecmascript-6ngrx-storengrx-effects

解决方案


推荐阅读