JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 101
  • Score
    100M100P100Q78041F
  • License Apache-2.0

A lib to reduce the boilterplate of redux asynchronous actions

Package Exports

  • redux-act-async

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-act-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

redux-act-async

Create async actions based on react-act

Install

npm install redux-act-async --save

Usage

import thunk from 'redux-thunk'
import {createStore, applyMiddleware} from 'redux';
import thunkMiddleware from 'redux-thunk';
import {createReducer} from 'redux-act';
import {createActionAsync} from 'redux-act-async';

// The async api to call, must be a function that return a promise
let user = {id: 8};
function apiOk(){
  return Promise.resolve(user);
}

// createActionAsync will create 3 synchronous action creators: login.request, login.ok and login.error
const login = createActionAsync('LOGIN', apiOk);

const initialState = {
  authenticated: false,
};

let reducer = createReducer({
  [login.request]: (state, payload) => {
    console.log('login.request ', payload);
  },
  [login.ok]: (state, payload) => {
    console.log('login.ok ', payload);
  },
  [login.error]: (state, payload) => {
    console.log('login.error ', payload);
  }
}, initialState);


const store = createStore(reducer, applyMiddleware(thunk));

let run = login({username:'lolo', password: 'password'});

store.dispatch(run);