JSPM

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

A tool helps creating smart (sync or async) redux action.

Package Exports

  • redux-x-action

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-x-action) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Redux X Action

A tool helps creating smart (sync or async) redux action.

Installation

npm install --save redux-x-action

Then, to enable Redux X Action:

import { createStore, applyMiddleware } from 'redux';
import { createXMiddleware, createXReducer } from 'redux-x-action';

// Note: this API requires redux@>=3.1.0
const store = createStore(
  combineReducers( {
    xAction: createXReducer()
  } ),
  applyMiddleware( 
    createXMiddleware() 
  )
);

Basic Usage

Update state (Synchronous):

// dispatch
...
function updateState(newState) {
  return {
    type: 'UPDATE_STATE',
    xAction: {
      xStateName: 'stateName',
      xStateData: newState
    }
  };
}

store.dispatch(updateState('New State'));
...

// props mapping
...
const mapStateToProps = ( state ) => {
  return {
    propName: state.xAction.stateName
  }
};
...

Update state (Asynchronous):

// dispatch
...
function updateState(ms) {
  return {
    type: 'UPDATE_STATE',
    xAction: {
      xStateName: 'stateName',
      xAsync: () => {
        let promise = new Promise(resolve => setTimeout(resolve, ms));
        return promise;
      }
    }
  };
}

store.dispatch(updateState(1000));
...

// props mapping
...
const mapStateToProps = ( state ) => {
  return {
    // async result including error 
    propName: state.xAction.stateName, 
    // async status: X_STATE_VALUE_ASYNC_RUNNING, X_STATE_VALUE_ASYNC_SUCCESS or X_STATE_VALUE_ASYNC_FAILURE
    // import { X_STATE_VALUE_ASYNC_RUNNING, X_STATE_VALUE_ASYNC_SUCCESS, X_STATE_VALUE_ASYNC_FAILURE } from 'redux-x-action';
    propAsyncStatus: state.xAction.xAsyncStatus
  }
};
...

Advanced Usage

TODO

License

Apache-2.0