微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有一个使用网络套接字和使用ngrx / store的redux的Ionic 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;
  }
}

在我的rootReducers中

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

export function rootReducer () {
  return {
    reducers: {
      driverUpdateProfile: DriverUpdateProfileReducer,},}
}

在我的app.module.ts中

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

// and in the **imports arrays**

StoreModule.forRoot({
  ...rootReducer().reducers
}),

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

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

解决方法

我设法通过改变我实现rootReducer和rootActions的方式来解决问题.我没有导出函数,而是返回声明的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,}
  }
}

这是下面的新代码

export const rootActions = {
  newLocation: NewLocation,}

export const rootReducer = {
  newLocation: NewLocationReducer,}

我将它们分为两个独立的变量,我认为它更有条理而不是旧的变量.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐