-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add redux-form driver #74
Comments
FYI @guillaumecrespel @bpetetot I just changed the example about Maybe we should rename |
maybe : const asyncSubmit = (name, dispatch, getState) => async (promise, ...args) => { |
this is not a promise this a callback that returns a promise |
And be careful, your not sure that the form will be in getFormValues: () => getFormValues(name, state => state.ui.form)(getState()), |
Yes you are right, this is something to think about :) |
The driver should be currified to give this accessor: instanciation import { createStore } from 'k-ramel'
import form from '@k-ramel/driver-reduxform'
export default createStore(
{/* */},
{
drivers: {
form: form(store => store.ui.form),
}
}
) driver source code import { setSubmitSucceeded, getFormValues, setSubmitFailed, startSubmit, stopSubmit, isSubmitting } from 'redux-form'
const asyncSubmit = (name, { getState, dispatch }) => async (callback, ...options) => {
dispatch(startSubmit(name))
await callback(...options)
if (isSubmitting(name)(getState())) dispatch(stopSubmit)
}
export default selector => store => (name) =>
const { dispatch, getState } = store
return {
getFormValues: () => getFormValues(name, selector(store))(getState()),
setSubmitFailed: (...fields) => dispatch(setSubmitFailed(name, ...fields)),
setSubmitSucceeded: () => dispatch(setSubmitSucceeded(name)),
startSubmit: () => dispatch(startSubmit(name)),
stopSubmit: errors => dispatch(stopSubmit(name, errors)),
asyncSubmit: (callback, ...options) => asyncSubmit(name, store)(callback, ...options),
}
} |
Be careful there is a typo here : const asyncSubmit = (name, { getState, dispatch }) => async (callback, ...options) => {
dispatch(startSubmit(name))
await callback(...options)
// error calling stopSubmit
if (isSubmitting(name)(getState())) dispatch(stopSubmit(name))
} |
And the async function should return a response (for example with http post) : const asyncSubmit = (name, { getState, dispatch }) => async (callback, ...options) => {
dispatch(startSubmit(name))
const response = await callback(...options)
// error calling stopSubmit
if (isSubmitting(name)(getState())) dispatch(stopSubmit(name))
return response
} |
Waiting for #69 so the lib are not requiring
redux-form
everytime... for everycases.driver
Example usage in a reaction (plugued to a listener)
The text was updated successfully, but these errors were encountered: