Comments (8)
this is not a promise this a callback that returns a promise
from k-ramel.
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),
}
}
from k-ramel.
FYI @guillaumecrespel @bpetetot I just changed the example about asyncSubmit
so it passes http.post
And I changed the driver so it recieve a callback
and not http
.
Maybe we should rename callback
to promiseCallback ?
from k-ramel.
maybe :
const asyncSubmit = (name, dispatch, getState) => async (promise, ...args) => {
from k-ramel.
And be careful, your not sure that the form will be in state.ui.form
:
getFormValues: () => getFormValues(name, state => state.ui.form)(getState()),
from k-ramel.
Yes you are right, this is something to think about :)
from k-ramel.
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))
}
from k-ramel.
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
}
from k-ramel.
Related Issues (20)
- An in-range update of babel7 is breaking the build 🚨 HOT 1
- An in-range update of jest-environment-jsdom-global is breaking the build 🚨 HOT 1
- reset is triggered 2 times on k-redux-factory types HOT 1
- An in-range update of regenerator-runtime is breaking the build 🚨 HOT 1
- An in-range update of babel7 is breaking the build 🚨 HOT 24
- Corporate CSP preventing the use of "eval()" HOT 2
- connector/react | lifecycle HOT 1
- An in-range update of eslint is breaking the build 🚨 HOT 4
- An in-range update of eslint-plugin-react is breaking the build 🚨 HOT 1
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 2
- An in-range update of rollup-plugin-copy is breaking the build 🚨 HOT 3
- change orga name everywhere for next publication
- An in-range update of eslint-plugin-react is breaking the build 🚨 HOT 5
- An in-range update of babel-eslint is breaking the build 🚨 HOT 1
- An in-range update of eslint-plugin-react-hooks is breaking the build 🚨 HOT 2
- An in-range update of babel7 is breaking the build 🚨 HOT 12
- An in-range update of regenerator-runtime is breaking the build 🚨 HOT 1
- An in-range update of eslint-config-airbnb is breaking the build 🚨 HOT 1
- An in-range update of jest2 is breaking the build 🚨 HOT 14
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from k-ramel.