I have some example on 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)
);
}
How to implement same action creator in redux? Should I create action creator for every action type?
I'd probably let action creator return a function. If it's a function, it's given dispatch
and the state.
I added support for async ACs as described above. For now, they can't access the state—I'll probably get back to it at some point, but I don't want to rush an API.
Update: you can do this now.
// Could also look into state in the callback form
export function incrementIfOdd() {
return (dispatch, state) => {
if (state.counterStore.counter % 2 === 0) {
return;
}
dispatch(increment());
};
}
Most helpful comment
I'd probably let action creator return a function. If it's a function, it's given
dispatch
and the state.