Git Product home page Git Product logo

Comments (8)

fabienjuif avatar fabienjuif commented on May 24, 2024 1

this is not a promise this a callback that returns a promise

from k-ramel.

fabienjuif avatar fabienjuif commented on May 24, 2024 1

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.

fabienjuif avatar fabienjuif commented on May 24, 2024

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.

bpetetot avatar bpetetot commented on May 24, 2024

maybe :

const asyncSubmit = (name, dispatch, getState) => async (promise, ...args) => {

from k-ramel.

bpetetot avatar bpetetot commented on May 24, 2024

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.

fabienjuif avatar fabienjuif commented on May 24, 2024

Yes you are right, this is something to think about :)

from k-ramel.

bpetetot avatar bpetetot commented on May 24, 2024

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.

bpetetot avatar bpetetot commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.