Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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,}

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

大佬总结

以上是大佬教程为你收集整理的angular – Ionic 3 ngrx/store redurs仅在生产模式下不接收调度操作全部内容,希望文章能够帮你解决angular – Ionic 3 ngrx/store redurs仅在生产模式下不接收调度操作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: