Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

VinSpee/async-redux-actions

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Async Redux Action Creators

Travis Coverage Status npm bundle size (minified + gzip) Tested with Jest semantic-release Commitizen friendly Conventional Commits styled with prettier license

({
  prefix: String,
  states: [...String]
}) => ({ entity: String }) => {
  ...[String]: ReduxAction
}

install

yarn add -D async-redux-actions redux-actions

What

async-redux-actions is a small helper that uses redux-actions to create a set of action creators and action types that you can use for all of your app's actions. It helps you by taking an object of actions and returning a set of action creators and actions types.

Why

I like using redux-actions in conjunction with redux-promise-middleware, but felt icky about writing things like ${userActions.signIn.toString()}/RECEIVED.

How

// user.js

import createActions from 'async-redux-actions';

const actions = createActions({
  states: ['REQUESTED', 'RECEIVED', 'REJECTED'],
  prefix: 'πŸ’Ž',
}); // returns an function that is waiting on an entity and an object of actions.

export default actions({ entity: 'user ' })({
  PROFILE: promiseApi.getProfile,
});

That will create these action creators and types:

action creators

  • profile.requested()
  • profile.received()
  • profile.rejected()
  • profile()

along side of redux-promise-middleware, dispatching profile will kick off each action according to it's state, just like normal.

types

  • 'πŸ’Ž/USER/PROFILE/REQUESTED',
  • 'πŸ’Ž/USER/PROFILE/RECEIVED',
  • 'πŸ’Ž/USER/PROFILE/REJECTED'

here's a full sample