1.0.4 • Published 5 years ago

redux-promise-utils v1.0.4

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

redux-promise-utils

Based on redux-thunk & redux-actions.

Easy utils to handle Promise in redux.

Quick Start

Install

use npm

npm i redux-promise-utils --save

use yarn

yarn add redux-promise-utils

Usage

  1. Ensure your reducer is handled by redux-thunk.
  2. Ensure your api is a Promise.
// data/action.js
import { createPromiseAction } from 'redux-promise-utils'
import * as api from './api'

export const fetchAction = createPromiseAction('fetchList', api.fetchList)

// data/reducer.js
import { createReducer } from 'redux-promise-utils'
import { fetchAction } from './action'

const initState = {}

const reducer = createReducer(initState)
    // catch sync action
    .which('SYNC_ACTION', (state, action) => {
        return state
    })
    // catch async action with three state
    .asyncWhich(fetchAction, {
        start(state, action) {
            return state
        },
        success(state, action) {
            return state
        },
        fail(state, action) {
            return state
        }
    })
    // build redux reducer handler
    .build()

export default reducer
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago