bdn-pocket
Version:
pocket tools for managing redux and redux-saga
71 lines (53 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Types = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _it = require('@stamp/it');
var _it2 = _interopRequireDefault(_it);
var _is = require('@stamp/is');
var _is2 = _interopRequireDefault(_is);
var _action_type = require('./action_type');
var _action_type2 = _interopRequireDefault(_action_type);
var _prop_types = require('./prop_types');
var _prop_types2 = _interopRequireDefault(_prop_types);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Types = _prop_types.Types;
var Action = (0, _it2.default)(_prop_types2.default).conf({
actionType: (0, _action_type2.default)()
}).statics({
CONST: '',
prefix: function prefix(_prefix) {
if (!_is2.default.isString(_prefix)) {
throw new ReferenceError('expected prefix type is string - received ' + (typeof _prefix === 'undefined' ? 'undefined' : _typeof(_prefix)));
}
return this.conf({
actionType: (0, _action_type2.default)({ prefix: _prefix })
});
},
def: function def(name) {
if (!_is2.default.isString(name)) {
throw new ReferenceError('expected name type is string - received ' + (typeof name === 'undefined' ? 'undefined' : _typeof(name)));
}
var actionType = this.compose.configuration.actionType;
return this.statics({
CONST: actionType.getType(name)
});
}
}).props({
type: '',
payload: {}
}).init(function (props, _ref) {
var stamp = _ref.stamp,
instance = _ref.instance;
var CONST = stamp.compose.staticProperties.CONST;
if (CONST.length === 0) {
throw new Error('action has not name definition - use Action.def to init it');
}
instance.type = CONST;
instance.payload = props;
});
// const a = Action.def('a').propTypes('a')
// console.log(a({a: 'a'}))
exports.default = Action;