Fluceμ λν λͺ κ°μ§ μκ° μμ΅λλ€.
function authFormSubmit(fluce) {
const {valid, disabled, data: {username, password}} = fluce.stores.authForm
if (disabled) return
if (!valid) {
fluce.dispatch(AUTH_FORM_ERROR, new Error('Form is invalid'))
return
}
fluce.dispatch(AUTH_FORM_DISABLED, true)
fluce.dispatch(AUTH_FORM_ERROR, null)
authorize({username, password})
.then(
user => fluce.dispatch(CURRENT_USER, user),
error => fluce.dispatch(AUTH_FORM_ERROR, error)
)
.then(
() => fluce.dispatch(AUTH_FORM_DISABLED, false)
);
}
reduxμμ λμΌν μ‘μ μμ±κΈ°λ₯Ό ꡬννλ λ°©λ²μ 무μμ λκΉ? λͺ¨λ μμ μ νμ λν΄ μμ μμ±μλ₯Ό λ§λ€μ΄μΌ ν©λκΉ?
μλ§λ μ‘μ
μμ±μκ° ν¨μλ₯Ό λ°ννλλ‘ ν κ²μ
λλ€. ν¨μμΈ κ²½μ° dispatch
λ° μνκ° μ 곡λ©λλ€.
μμμ μ€λͺ ν λλ‘ λΉλκΈ° ACμ λν μ§μμ μΆκ°νμ΅λλ€. νμ¬λ‘μλ μνμ μ‘μΈμ€ν μ μμ΅λλ€. μΈμ κ°λ μ΄ μνλ‘ λμκ°κ² μ§λ§ APIλ₯Ό μλλ₯΄κ³ μΆμ§λ μμ΅λλ€.
μ λ°μ΄νΈ: μ§κΈ ν μ μμ΅λλ€.
// Could also look into state in the callback form
export function incrementIfOdd() {
return (dispatch, state) => {
if (state.counterStore.counter % 2 === 0) {
return;
}
dispatch(increment());
};
}
κ°μ₯ μ μ©ν λκΈ
μλ§λ μ‘μ μμ±μκ° ν¨μλ₯Ό λ°ννλλ‘ ν κ²μ λλ€. ν¨μμΈ κ²½μ°
dispatch
λ° μνκ° μ 곡λ©λλ€.