1.0.4 • Published 7 years ago
babel-plugin-redux-action-matching v1.0.4
babel-plugin-redux-action-matching
A babel transformer plugin that compares arrays in switch-case statements by elements, but not by reference.
Installation
npm install babel-plugin-redux-action-matching
.babelrc
{
"presets": [
["es2015", {"modules": false}],
"stage-2",
"react"
],
"plugins": [
"babel-plugin-redux-action-matching"
]
}
Usage
import {FETCH_ACCOUNTS, FETCH_TRANSACTIONS} from './actions';
import {FETCHING, SUCCESS, ERROR} from './actions';
function accountsData(state = {}, action) {
switch ([action.type, action.status]) {
case [FETCH_ACCOUNTS, FETCHING]:
return {
isFetching: true,
accounts: []
};
case [FETCH_ACCOUNTS, SUCCESS]:
return {
isFetching: false,
accounts: action.data
};
case [FETCH_ACCOUNTS, ERROR]:
return {
isFetching: false,
accounts: [],
error: action.error
};
default:
return state;
}
}