redux-crud-actions
v0.5.1
Published
Standard CRUD actions for Redux
Downloads
2
Readme
Redux CRUD Actions
Standard CRUD actions for redux
Install
npm install redux-crud-actions --save-dev
.actionCreatorsFor
Creates an object with standard CRUD action creators.
var crudActions = require('redux-crud-actions');
var actionCreators = crudActions.actionCreatorsFor('users');
// actionCreators =>
{
fetchStart: function() {
return {
type: 'USERS_FETCH_START',
};
},
fetchSuccess: function(payload) {
return {
type: 'USERS_FETCH_SUCCESS',
users: payload,
};
},
fetchError: function(error) {
return {
type: 'USERS_FETCH_ERROR',
error: error
};
},
createStart: function(payload) {
return {
type: 'USERS_CREATE_START',
users: payload,
};
},
createSuccess: function(payload) {
return {
type: 'USERS_CREATE_SUCCESS',
users: payload,
};
},
createError: function(error, payload) {
return {
type: 'USERS_CREATE_ERROR',
error: error
users: payload,
};
},
updateStart: function(payload) {
return {
type: 'USERS_UPDATE_START',
users: payload,
};
},
updateSuccess: function(payload) {
return {
type: 'USERS_UPDATE_SUCCESS',
users: payload,
};
},
updateError: function(error, payload) {
return {
type: 'USERS_UPDATE_ERROR',
error: error
users: payload,
};
},
deleteStart: function(payload) {
return {
type: 'USERS_DELETE_START',
users: payload,
};
},
deleteSuccess: function(payload) {
return {
type: 'USERS_DELETE_SUCCESS',
users: payload,
};
},
deleteError: function(error, payload) {
return {
type: 'USERS_DELETE_ERROR',
error: error
users: payload,
};
}
}
.actionTypesFor
Creates an object with standard CRUD action types.
var crudActions = require('redux-crud-actions');
var actionTypes = crudActions.actionTypesFor('users');
// actionTypes =>
{
USERS_FETCH_START: 'USERS_FETCH_START',
USERS_FETCH_SUCCESS: 'USERS_FETCH_SUCCESS',
USERS_FETCH_ERROR: 'USERS_FETCH_ERROR',
USERS_UPDATE_START: 'USERS_UPDATE_START',
USERS_UPDATE_SUCCESS: 'USERS_UPDATE_SUCCESS',
USERS_UPDATE_ERROR: 'USERS_UPDATE_ERROR',
USERS_CREATE_START: 'USERS_CREATE_START',
USERS_CREATE_SUCCESS: 'USERS_CREATE_SUCCESS',
USERS_CREATE_ERROR: 'USERS_CREATE_ERROR',
USERS_DELETE_START: 'USERS_DELETE_START',
USERS_DELETE_SUCCESS: 'USERS_DELETE_SUCCESS',
USERS_DELETE_ERROR: 'USERS_DELETE_ERROR',
// Object also contains shortcuts
fetchStart: 'USERS_FETCH_START',
fetchSuccess: 'USERS_FETCH_SUCCESS',
fetchError: 'USERS_FETCH_ERROR',
updateStart: 'USERS_UPDATE_START',
updateSuccess: 'USERS_UPDATE_SUCCESS',
updateError: 'USERS_UPDATE_ERROR',
createStart: 'USERS_CREATE_START',
createSuccess: 'USERS_CREATE_SUCCESS',
createError: 'USERS_CREATE_ERROR',
deleteStart: 'USERS_DELETE_START',
deleteSuccess: 'USERS_DELETE_SUCCESS',
deleteError: 'USERS_DELETE_ERROR',
}