ginniecodes / reshort

write less in your action creators!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

reshort

Generated with nod NPM version Build Status Coverage Status

Sometimes we write too much repetition in our action creators.

Like so:

export const fetchProducts = () => ({
  type: FETCH_PRODUCTS
})

export const fetchProductsSuccessful = payload => ({
  type: FETCH_PRODUCTS_SUCCESSFUL,
  payload
})

export const fetchProductsFailure = error => ({
  type: FETCH_PRODUCTS_FAILURE,
  payload: error
})

export const fetchUsers = () => ({
  type: FETCH_USERS
})

export const fetchUsersSuccessful = payload => ({
  type: FETCH_USERS_SUCCESSFUL,
  payload
})

export const fetchUsersFailure = error => ({
  type: FETCH_USERS_FAILURE,
  payload: error
})

This library tries to remove this repetion encapsulating common actions in an action generator.

Install

$ npm install --save reshort

Usage

import reshort from "reshort";

const productsActions = reshort("Products");

productsActions("request")
// {
//   type: "GET_PRODUCTS"
// }

productsActions("success", {test: 123})
// {
//   type: "GET_PRODUCTS_SUCCESSFUL",
//   payload: { test: 123 }
// }

productsActions("fail", {test: "error"})
// {
//   type: "GET_PRODUCTS_FAILURE",
//   payload: { test: "error" }
// }

License

MIT © Robson Porto

About

write less in your action creators!

License:MIT License


Languages

Language:JavaScript 100.0%