GithubHelp home page GithubHelp logo

viniciusdacal / redux-arc Goto Github PK

View Code? Open in Web Editor NEW
160.0 9.0 13.0 1.04 MB

A declarative way to make request with redux actions

Home Page: http://redux-arc.js.org

License: MIT License

JavaScript 99.55% CSS 0.45%
redux middleware react async requests

redux-arc's People

Contributors

fquinner avatar shodanuk avatar viniciusdacal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redux-arc's Issues

Calling two reducers from action handler

Is there a sensible way to do this?

I'm calling an api endpoint which returns two sets of data which need to be handled by separate reducers, is there a better way to do it than to listen to the RESPONSE action type in both reducers?

create reducers and selectors factory.

Having the types objects and knowing the action format, we can easily create the reducers.

Points to evaluate: Do we add this in the same package or create another one for it?

Error: attempting to change value of a readonly property

Environment:

  • npm: v6.0.0
  • package.json:
      "expo": "^27.0.1",
      "native-base": "^2.7.0",
      "react": "16.3.1",
      "react-native": "~0.55.2",
      "react-native-odoo": "^0.5.0",
      "react-native-side-menu": "^1.1.3",
      "react-native-table-component": "^1.1.8",
      "react-navigation": "^2.6.2",
      "react-navigation-redux-helpers": "^2.0.2",
      "react-redux": "^5.0.7",
      "redux": "^4.0.0",
      "redux-arc": "^0.7.3",
      "redux-thunk": "^2.3.0",
      "rnpm": "^1.9.0",
      "xmldom": "^0.1.27"
    

I'm developing a React Native Expo app. It've set the Strict Mode (Expo do it as default).
In this scenario when fsaActionCreatorFactory.js try to execute the following code:

...
  Object.defineProperty(actionCreator, 'name', {
    value: type + ' action creator',
    writable: false
  });
...

the error on the attached image is printed out.
ErrorImage.
The property name of the function actionCreator is set as read only. In this way we are trying to force a "set value" and this is forbidden.
If I run the app in debug mode (with Strict Mode deactivated) it works fine!

Optional query parameters in GET async actions

Hi,
At work we're successfully using this library in both a React and React Native project and it saved us a ton of boilerplate code (perhaps you remember me since the previous compilation issue with react native :-) ).
We're now at the point where we'd like to have a way to set optional query parameters in GET requests to tell our backend how to filter data.

Example:
To my knowledge, the library provides the current options to make a GET request to an example resource ( I added a possible back end expected response on the right based on our current back end behaviour)

Request BE response
GET resource/ all exams
GET resource/:customParameter single resource based on customParameter (like id)

I'd like to have a way to add query parameters to the get request, such as:

Request BE response
GET resource/?exampleFilter=:someCustomFIlter n resources based on exampleFilter parameter (exampleFilter could be any parameter name and should be parametrized in some way as well as the payload)

We went on with this by duplicating and dispatching different custom actions (each one for every possible query params, since we only have like 3 or 4 combinations and just in some specific cases).
Is there a "smarter" way to do this?
Am I missing something?

Thank you very much, and again, kudos for the great work on this library.

Merge passed payload with defaults

Is there a way to merge the payload passed to the action creator with the defaults provided in createActions ?

I have the following createActions:

export const { creators, types } = createActions('posts', {
  ...
  list: {
    url: '/posts/retrieve',
    method: 'get',
    payload: {
      'options[next]': 0,
      'options[limiter]': 0,
      'options[size]': 10,
      'filter[mode]': 'archive'
    }
  }
...
})

which is called from:

const mapDispatchToProps = (dispatch) => {
  const payload = {
    'options[next]': 0,
    'options[limiter]': 0,
    'options[size]': 10,
    'filter[mode]': 'drafts'
  }
  return {
    fetchData: () => { dispatch(posts.list(payload)) }
  }
}

but it would be nice if we could do:

const mapDispatchToProps = (dispatch) => {
  const payload = {
    'filter[mode]': 'drafts'
  }
  return {
    fetchData: () => { dispatch(posts.list(payload)) }
  }
}

and the payload would get merged with the defaults

Missing type definition for typescript

As stated in the title I can't find any type definition to use this lib with typescript.
At the moment I added the

// @ts-ignore

comment before the import but it's only a workaround.
Any suggestion?

Appending state item to async task url

Me again....

Many of the api endpoints in our application require a profileId in the url, eg:

/articles/:profileId/:id

The profileId is stored in the state and previously, when using redux-saga (which we are replacing with redux-arc ๐Ÿ™‚) we could get it before making the api call.

Is there a smart way of doing this with redux-arc?

We could intercept the api call with a middleware and detect the :profileId in the url with regex and replace it with the item from the state?

Currently we are getting it in mapStateToProps then passing down to the component then back up to mapDispatchToProps via event handlers which feels a bit messy

Global middlewares

Is there a way to add global middlewares to every request?

I want to add a token string to every request (if there currently is one), at the moment i'd have to do something like this on every creator

const { types, creators } = createActions('posts', {
  list: {
    url: 'posts',
    method: 'get',
    middlewares: [addTokenMiddleware],
  },
})

Also, do we have access to the redux state from middlewares? I'd like the get the token from the state and add it if it exists

Allow passing params to policies in the requests config

Currently, the only way to provide params to the policies is by add them when you call the creator.

Would be better to allow passing the params in the requests configs. This way, we could use a policy this way:

const { creators, types } = createApiActions('namespace', {
  list: {
    url: 'enpoint',
    method: 'get',
    policies: ['anyPolicy', { name: 'policyWithParams', ...params }]
  }
});

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.