Ionic 3 ngrx/store reducers仅在生产模式下不接收调度操作

Kno*_*ker 6 ionic-framework redux ionic3 angular ngrx-store

我有一个使用网络套接字和使用ngrx/store的reduxIonic 3应用程序.起初我的所有代码都在开发模式下正常工作.在浏览器和真实设备中.

但是当我尝试在生产模式下构建它时.仍然会调度该操作,但reducers没有收到已分派的操作,导致应用程序的状态未更新.

这是我的减速机下面的代码.

import { Action } from '@ngrx/store';

const UPDATE_AVATAR = '[Websokcet] New ORDER';
type Type = UpdateAvatar

export class UpdateAvatar implements Action {
  readonly type = UPDATE_AVATAR;
  constructor(public payload: any) { }
}

export function UpdateAvatarReducer(state: any, action: Type) {
  console.log('ACTION RECEIVED:', state, action)
  switch (action.type) {
    case UPDATE_AVATAR:
      return action.payload;
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的rootReducers中

import { UpdateAvatar, UpdateAvatarReducer } from './reducers/uploadAvatar';

export function rootReducer () {
  return {
    reducers: {
      driverUpdateProfile: DriverUpdateProfileReducer,
    },
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的app.module.ts中

import { rootReducer } from '../store/websocket';

// and in the **imports arrays**

StoreModule.forRoot({
  ...rootReducer().reducers
}),
Run Code Online (Sandbox Code Playgroud)

它在开发模式下工作,但它不在生产中.为什么?

感谢有人可以提供帮助.提前致谢.

Kno*_*ker 4

我设法通过改变实现rootReducerrootActions的方式来解决这个问题。我没有导出函数,而是返回了声明的 2 个单独的对象。

这是我的rootReducer操作的旧代码

export default function () {
  return {
    reducers: {
      newLocation: NewLocationReducer,
      newOrder: NewOrderReducer,
      orderTaken: OrderTakenReducer,
      driverUpdateProfile: DriverUpdateProfileReducer,
      driverUpdateAvatar: UpdateAvatarReducer,
      newTransaction: NewTransactionReducer,
      updateTransaction: UpdateTransactionReducer,
      orderNewMessage: OrderNewMessageReducer,
    },
    actions: {
      newLocation: NewLocation,
      newOrder: NewOrder,
      orderTaken: OrderTaken,
      driverUpdateProfile: DriverUpdateProfile,
      driverUpdateAvatar: UpdateAvatar,
      newTransaction: NewTransaction,
      updateTransaction: UpdateTransaction,
      orderNewMessage: OrderNewMessage,
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这是下面的新代码:

export const rootActions = {
  newLocation: NewLocation,
  newOrder: NewOrder,
  orderTaken: OrderTaken,
  driverUpdateProfile: DriverUpdateProfile,
  driverUpdateAvatar: UpdateAvatar,
  newTransaction: NewTransaction,
  updateTransaction: UpdateTransaction,
  orderNewMessage: OrderNewMessage,
}

export const rootReducer = {
  newLocation: NewLocationReducer,
  newOrder: NewOrderReducer,
  orderTaken: OrderTakenReducer,
  driverUpdateProfile: DriverUpdateProfileReducer,
  driverUpdateAvatar: UpdateAvatarReducer,
  newTransaction: NewTransactionReducer,
  updateTransaction: UpdateTransactionReducer,
  orderNewMessage: OrderNewMessageReducer,
}
Run Code Online (Sandbox Code Playgroud)

我将它们声明为两个独立的变量,我认为它比旧的更有组织性。