0.2.0 • Published 6 years ago

redux-awesome-sauce v0.2.0

Weekly downloads
14
License
MIT
Repository
github
Last release
6 years ago

Redux Helpers

This is a simple fork of https://github.com/infinitered/reduxsauce

Most of the original documentation stands, with a few differences, as can be seen in this code example:

// Added `createApiActions`
import {
  createActions,
  createApiActions,
} from 'redux-awesome-sauce'

// I've opted to lowercase `types` and `creators`...
const { types, creators } = createActions(
  {
    logout: ['user'],
    requestWithDefaultValues: {
      username: 'guest',
      password: null,
    },
    custom: (a, b) => ({ type: 'CUSTOM', total: a + b }),
  },
  {}, // options - the 2nd parameter is optional
)

// For better or for worse, arguments are nested under `payload`:
const { logout } = creators

logout('abustamam') // { type: 'LOGOUT', payload: { user: 'abustamam '}}

// Using `createApiActions`:

const {
  types: apiTypes,
  creators: apiCreators,
} = createApiActions({
  login: {
    request: ['user', 'password'],
    success: ['response'],
    failure: ['error'],
  },
})

const {
  LOGIN_REQUEST,
  LOGIN_SUCCESS,
  LOGIN_FAILURE,
} = apiTypes
const {
  loginRequest,
  loginSuccess,
  loginFailure,
} = apiCreators
loginRequest('abustamam', 'foobar')
// {
//   type: 'LOGIN_REQUEST',
//   payload: { user: 'abustamam', password: 'foobar' }
// }

Those are the additions I made, and it makes working with redux sagas a lot simpler.

If you want to use redux-dataloader, just add the useLoader option:

const {
  types: apiTypes,
  creators: apiCreators,
} = createApiActions({
  login: {
    request: ['user', 'password'],
    success: ['response'],
    failure: ['error'],
  },
}, { useLoader: true })
0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago