1.0.1 • Published 5 years ago

redux-thunk-action-helpers v1.0.1

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

npm version Build Status Coverage Status Inline docs Hit Count Build Dependencies Dev Dependencies

NPM

contributions welcome

Installation

install

$ npm i redux-thunk-action-helpers 
$ yarn add redux-thunk-action-helpers

Motivation

Thunk actions usually follow the same rules. Dispatch start action, run some code, dispatch the result on the sucess action or dispatch the error on the fail action

Example

action types

import { createActionTypes } from 'redux-thunk-action-helpers';

export const userActionTypes = createActionTypes('my-app', 'FETCH', 'SUBMIT');

/*
 * userActionTypes = {
 *  FETCH : '@@my-app/FETCH',
 *  FETCH_START : '@@my-app/FETCH_START',
 *  FETCH_SUCCESS : '@@my-app/FETCH_SUCCESS',
 *  FETCH_ERROR : '@@my-app/FETCH_ERROR',
 *  SUBMIT : '@@my-app/SUBMIT',
 *  SUBMIT_START : '@@my-app/SUBMIT_START',
 *  SUBMIT_SUCCESS : '@@my-app/SUBMIT_SUCCESS',
 *  SUBMIT_ERROR : '@@my-app/SUBMIT_ERROR',
 * }
 */

action creator

import { createActionCreator } from 'redux-thunk-action-helpers';

export const doFetchUsers = createActionCreator('GET_USERS', (page, limit) => api.getUsers(page, limit));

API

createActionTypes(namespace, ...types);


createActionCreator(type, fn);

fn = (...args, { dispatch, getState, extra }) => Promise/Value

License

MIT