redux-action-reducer-generator
A generator function to automate the creation of redux actions and reducers
Last updated a year ago by drive-override .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install redux-action-reducer-generator 
SYNC missed versions from official npm registry.

travis codecov

Intro

The redux-action-reducer package helps to automatically generate default actions and reducers and action constants with REQUEST, SUCCESS and FAILURE slugs.

Initialization

  import Generator from "redux-action-reducer-generator";

  const getPosts = new Generator("get_posts");

  // Add reducer to store
  const reducers = combineReducers({
    posts: getPosts.reducer
  })

  const store = createStore(reducers);

Explaination

Taking our previous example, our redux generator object contains the following action constants:

  • getPosts.REQUEST => GET_POSTS_REQUEST
  • getPosts.SUCCESS => GET_POSTS_SUCCESS
  • getPosts.FAILURE => GET_POSTS_FAILURE

If you want to call the appropriate action all you have to do is calling the method containing the request, success or failure function.

  // calling the request action
  getPosts.request();

This will trigger the reducer to update the state property isLoading to true.

  getPosts.success("foo");

When calling the success method simply pass anything you want to update your sate with. This will automatically set the states isLoading property to false and set the done property to true.

Same works with the .failure("error"); method. Passing in your error message or object will trigger setting the state isLoading to false as well as in success, but setting done to false.


Contributing

See CONTRIBUTE.md.

Current Tags

  • 1.0.7                                ...           latest (a year ago)

8 Versions

  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (0)
None
Dev Dependencies (13)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |