angular – Ionic 3 ngrx/store redurs仅在生产模式下不接收调度
发布时间:2020-12-17 07:11:13 所属栏目:安全 来源:网络整理
导读:我有一个使用网络套接字和使用ngrx / store的redux的Ionic 3应用程序.起初我的所有代码都在开发模式下正常工作.在浏览器和真实设备中. 但是当我尝试在生产模式下构建它时.仍然会调度该操作,但reducers没有收到已分派的操作,导致应用程序的状态未更新. 这是我
我有一个使用网络套接字和使用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,} 我将它们分为两个独立的变量,我认为它更有条理而不是旧的变量. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容