redux-easy2-crud
Version:
Easy crud programming with Redux
62 lines (47 loc) • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createOrUpdate = exports.crudError = exports.delSuccess = exports.del = exports.updateSuccess = exports.update = exports.createSuccess = exports.create = exports.readSuccess = exports.read = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _docs = require("../constants/docs");
var TYPES = _interopRequireWildcard(_docs);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var read = exports.read = function read(path) {
return { path: path, type: TYPES.READ };
};
var readSuccess = exports.readSuccess = function readSuccess(path, docs) {
return { path: path, docs: docs, type: TYPES.READ_SUCCESS };
};
var create = exports.create = function create(path, doc) {
return _extends({}, doc, { path: path, type: TYPES.CREATE });
};
/**
* Success creation
* @param doc The object created. A path and id attribute has been injected on the object which will permit to identify its category
*/
var createSuccess = exports.createSuccess = function createSuccess(doc) {
return _extends({}, doc, { type: TYPES.CREATE_SUCCESS });
};
/**
* Update CRUD action
* @param doc The ressource to modify. This ressource must contains a path attribut permitting to identify its type and a id attribute
*/
var update = exports.update = function update(doc) {
return _extends({}, doc, { type: TYPES.UPDATE });
};
var updateSuccess = exports.updateSuccess = function updateSuccess(doc) {
return _extends({}, doc, { type: TYPES.UPDATE_SUCCESS });
};
var del = exports.del = function del(doc) {
return _extends({}, doc, { type: TYPES.DELETE });
};
var delSuccess = exports.delSuccess = function delSuccess(doc) {
return _extends({}, doc, { type: TYPES.DELETE_SUCCESS });
};
var crudError = exports.crudError = function crudError(type, path, error) {
return { type: type, path: path, error: error };
};
var createOrUpdate = exports.createOrUpdate = function createOrUpdate(path, doc) {
if (doc.id) return update(doc);else return create(path, doc);
};