2017-01-30 71 views
0

使用@ NGRX /商店內這個錯誤彈出:狀態突變禁止減速

index.js?4b23:19 State mutation is prohibited inside of reducers. 
(anonymous) @ index.js?4b23:19 
(anonymous) @ index.ts:54 
rootReducer @ index.ts:70 
_initialStateFactory @ ng2.ts?2a33:24 
AppModuleInjector.createInternal @ module.ngfactory.js:425 
NgModuleInjector.create @ ng_module_factory.js?95b1:132 
NgModuleFactory.create @ ng_module_factory.js?95b1:100 
(anonymous) @ application_ref.js?0421:340 
ZoneDelegate.invoke @ zone.js?e3a6:229 
onInvoke @ ng_zone.js?b62b:269 
ZoneDelegate.invoke @ zone.js?e3a6:228 
Zone.run @ zone.js?e3a6:113 
NgZone.run @ ng_zone.js?b62b:138 
PlatformRef_._bootstrapModuleFactoryWithZone @ application_ref.js? 0421:338 
(anonymous) @ application_ref.js?0421:389 
ZoneDelegate.invoke @ zone.js?e3a6:229 
Zone.run @ zone.js?e3a6:113 
(anonymous) @ zone.js?e3a6:509 
ZoneDelegate.invokeTask @ zone.js?e3a6:262 
Zone.runTask @ zone.js?e3a6:151 
drainMicroTaskQueue @ zone.js?e3a6:405 
ZoneTask.invoke @ zone.js?e3a6:336 
main.browser.ts:18 TypeError: Cannot set property 'actions$' of undefined 
at CatBibleEffects (catBible.effects.ts:15) 
at combination (utils.ts?b1fc:23) 
at index.js?39b4:125 
at index.js?4b23:16 
at index.ts:54 
at rootReducer (index.ts:70) 
at _initialStateFactory (ng2.ts?2a33:24) 
at AppModuleInjector.createInternal (module.ngfactory.js:425) 
at AppModuleInjector.NgModuleInjector.create (ng_module_factory.js?95b1:132) 
at NgModuleFactory.create (ng_module_factory.js?95b1:100) 
at application_ref.js?0421:340 
at ZoneDelegate.invoke (zone.js?e3a6:229) 
at Object.onInvoke (ng_zone.js?b62b:269) 
at ZoneDelegate.invoke (zone.js?e3a6:228) 
at Zone.run (zone.js?e3a6:113) 

回答

1

此錯誤無關,與我的影響文件或我的行動文件。從類似的文件複製後,我忘了重命名reducer功能。這也導致這個reducer的調用在主根reducer文件中被錯誤地命名。

2

State mutation is prohibited inside of reducers錯誤似乎錯誤時,從減速抓到要返回......這裏的ngrx-store-freeze/dist/index.js代碼中返回此錯誤catch住...

function storeFreeze(reducer) { 
    return function (state, action) { 
     if (state === void 0) { state = {}; } 
     deepFreeze(state); 
     // guard against trying to freeze null or undefined types 
     if (action.payload) { 
      deepFreeze(action.payload); 
     } 
     var nextState; 
     try { 
      nextState = reducer(state, action); 
     } 
     catch (error) { 
      console.error('State mutation is prohibited inside of reducers.'); 
      throw error; 
     } 
     deepFreeze(nextState); 
     return nextState; 
    }; 
} 
exports.storeFreeze = storeFreeze; 

因此你的錯誤可能真正成爲相關以說明被不恰當地更改或它可能只是意味着一個未被捕獲的錯誤傳播到您的還原器的呼叫...

+1

感謝您指出這一點。這是一個與ngrx的錯誤,它不應該這樣做,它應該顯示底層的錯誤。 – Purrell