哎呀,我覺得愚蠢關於這一點,但我看過的每一個部分:http://redux.js.org/(做了理論家的教程,並在閱讀4次FAQ:http://redux.js.org/docs/faq/ImmutableData.htmlRedux會在每次分派操作時執行所有訂閱回調?
我所做的是存根我減速的一個,總是返回狀態,這是唯一被調用的reducer(用斷點檢查)即使如此,我的訂閱事件每次reducer返回狀態都會被調用,我不明白什麼?(Action.SetServerStats以1Hz的速率調用,並且訂閱也被稱爲1Hz Rate
BTW Chrome Redux Extension表示狀態是相同的,並且React Extension for Chrome with Trace React Updates ,沒有顯示任何更新。
當有人給我提供線索時,我會很高興刪除這個問題。但是現在,我看到每個減速器都以1Hz被調用,並且他們都返回了他們獲得的商店的切片(州)。
所以我不明白訂閱,並且它返回每個偶數當商店樹沒有得到修改的時間(這是由反應,終極版做淺比較弄清楚如果有的話是什麼改變了?)
創造店&訂閱
let store = createStore(reducer, initialState, composeWithDevTools(applyMiddleware(thunk)))
store.subscribe(() => console.log("current store: ", JSON.stringify(store.getState(), null, 4)))
reducers.js
import A from './actionTypes'
import { combineReducers } from 'redux'
export const GLVersion = (state = '', action) => {
switch (action.type) {
case A.SetGLVersion:
return action.payload
default:
return state
}
}
export const ServerConfig = (state = {}, action) => {
switch (action.type) {
case A.SetServerConfig: {
let { ServerPort, UserID, PortNumber, WWWUrl, SourcePath, FMEPath } = action.payload
let p = { ServerPort, UserID, PortNumber, WWWUrl, SourcePath, FMEPath }
return p
}
default:
return state
}
}
export const ServerStats = (state = {}, action) => {
switch (action.type) {
case A.SetServerStats:
return state
// let { WatsonInstalled, WatsonRunning, FMERunning, JobsDirSize } = action.payload
// let s = { WatsonInstalled, WatsonRunning, FMERunning, JobsDirSize }
// return s
default:
return state
}
}
export default combineReducers({ GLVersion, ServerConfig, ServerStats })