反応、還元、反応還元、還元サンクを使用するアプリケーションがあります。反応還元還元サンク:発送性能問題
react: "16.0.0-alpha.6"
redux: "3.6.0"
react-redux: "5.0.2"
redux-thunk: "2.1.0"
コンセプト:
リデューサー:
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
export const MESSAGES_ADD_MESSAGE = 'MESSAGES_ADD_MESSAGE';
export const CONTACTS_ADD_CONTACT = 'CONTACTS_ADD_CONTACT';
export default function messages(state = { messages: [] }, action) {
switch (action.type) {
case MESSAGES_ADD_MESSAGE:
return { messages: [ ...state.messages, action.message ] };
default:
return state;
}
}
export default function contacts(state = { contacts: [] }, action) {
switch (action.type) {
case CONTACTS_ADD_CONTACT:
return { contacts: [ ...state.contacts, action.contact ] };
default:
return state;
}
}
const rootReducer = combineReducers({
contacts,
messages
});
ストア:
const createStoreWithMiddleware = applyMiddleware(
thunkMiddleware
)(createStore);
const store = createStoreWithMiddleware(rootReducer);
アクションクリエイター:
export function addMessage(message) {
return {
type: MESSAGES_ADD_MESSAGE,
message
};
}
export function addContact(contact) {
return {
type: CONTACTS_ADD_CONTACT,
contact
};
}
ディスパッチの時間(addContact( 'Viktor +123456789'))は、ストア内のメッセージ数に応じて増加するのはなぜですか?
私は新しい店舗構成の時代を理解しているので、メッセージリデューサーはこの店舗の新しい部分を作成せずに状態参照を返します。
私はもっと複雑な実際のケースを持っていますが、問題の概念は似ています。
ただし、この場合、減速機のスイッチオペレータのデフォルトのケースは何ですか? –
デフォルトの場合は状態を変更していないので、参照を返すことは安全です。 – Akhil
「dispatch(addContact( 'Viktor +123456789'))」中にメッセージの状態が変化していない場合、ストア内のメッセージ数に応じてこのアクションの時間が増加する理由を教えてください。 –